Skip to content

Commit

Permalink
Part: [skip ci] move grid handling from ViewProvider2DObject to ViewP…
Browse files Browse the repository at this point in the history
…rovider2DObjectGrid
  • Loading branch information
wwmayer committed Aug 7, 2020
1 parent 6592a76 commit da5bd65
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/Mod/Part/Gui/AppPartGui.cpp
Expand Up @@ -162,6 +162,7 @@ PyMOD_INIT_FUNC(PartGui)
PartGui::ViewProviderExtrusion ::init();
PartGui::ViewProvider2DObject ::init();
PartGui::ViewProvider2DObjectPython ::init();
PartGui::ViewProvider2DObjectGrid ::init();
PartGui::ViewProviderMirror ::init();
PartGui::ViewProviderFillet ::init();
PartGui::ViewProviderChamfer ::init();
Expand Down
89 changes: 50 additions & 39 deletions src/Mod/Part/Gui/ViewProvider2DObject.cpp
Expand Up @@ -57,17 +57,17 @@ using namespace std;
//**************************************************************************
// Construction/Destruction

const char* ViewProvider2DObject::GridStyleEnums[]= {"Dashed","Light",NULL};
App::PropertyQuantityConstraint::Constraints ViewProvider2DObject::GridSizeRange = {0.001,DBL_MAX,1.0};
const char* ViewProvider2DObjectGrid::GridStyleEnums[]= {"Dashed","Light",NULL};
App::PropertyQuantityConstraint::Constraints ViewProvider2DObjectGrid::GridSizeRange = {0.001,DBL_MAX,1.0};

PROPERTY_SOURCE(PartGui::ViewProvider2DObject, PartGui::ViewProviderPart)
PROPERTY_SOURCE(PartGui::ViewProvider2DObjectGrid, PartGui::ViewProvider2DObject)

ViewProvider2DObject::ViewProvider2DObject()
ViewProvider2DObjectGrid::ViewProvider2DObjectGrid()
{
ADD_PROPERTY_TYPE(ShowGrid,(false),"Grid",(App::PropertyType)(App::Prop_None),"Switch the grid on/off");
ADD_PROPERTY_TYPE(ShowOnlyInEditMode,(true),"Grid",(App::PropertyType)(App::Prop_None),"Show only while in edit mode");
ADD_PROPERTY_TYPE(GridSize,(10.0),"Grid",(App::PropertyType)(App::Prop_None),"Gap size of the grid");
ADD_PROPERTY_TYPE(GridStyle,((long)0),"Grid",(App::PropertyType)(App::Prop_None),"Appearance style of the grid");
ADD_PROPERTY_TYPE(GridStyle,(0L),"Grid",(App::PropertyType)(App::Prop_None),"Appearance style of the grid");
ADD_PROPERTY_TYPE(TightGrid,(true),"Grid",(App::PropertyType)(App::Prop_None),"Switch the tight grid mode on/off");
ADD_PROPERTY_TYPE(GridSnap,(false),"Grid",(App::PropertyType)(App::Prop_None),"Switch the grid snap on/off");
ADD_PROPERTY_TYPE(GridAutoSize,(true),"Grid",(App::PropertyType)(App::Prop_Hidden),"Autosize grid based on shape boundbox");
Expand All @@ -86,15 +86,15 @@ ViewProvider2DObject::ViewProvider2DObject()
sPixmap = "Tree_Part2D";
}

ViewProvider2DObject::~ViewProvider2DObject()
ViewProvider2DObjectGrid::~ViewProvider2DObjectGrid()
{
GridRoot->unref();
}


// **********************************************************************************

SoSeparator* ViewProvider2DObject::createGrid(void)
SoSeparator* ViewProvider2DObjectGrid::createGrid(void)
{
//double dx = 10 * GridSize.getValue(); // carpet size
//double dy = 10 * GridSize.getValue();
Expand Down Expand Up @@ -202,7 +202,7 @@ SoSeparator* ViewProvider2DObject::createGrid(void)

int lines = vlines + hlines;

if( lines > maxNumberOfLines.getValue() ) { // If
if (lines > maxNumberOfLines.getValue()) {
Base::Console().Warning("Grid Disabled: Requested number of lines %d is larger than the maximum configured of %d\n.", lines, maxNumberOfLines.getValue());
parent->addChild(vts);
parent->addChild(grid);
Expand Down Expand Up @@ -241,12 +241,12 @@ SoSeparator* ViewProvider2DObject::createGrid(void)
return GridRoot;
}

void ViewProvider2DObject::updateData(const App::Property* prop)
void ViewProvider2DObjectGrid::updateData(const App::Property* prop)
{
ViewProviderPart::updateData(prop);
ViewProvider2DObject::updateData(prop);

if (prop->getTypeId() == Part::PropertyPartShape::getClassTypeId()) {
if(GridAutoSize.getValue()) {
if (GridAutoSize.getValue()) {
Base::BoundBox3d bbox = static_cast<const Part::PropertyPartShape*>(prop)->getBoundingBox();
if (!bbox.IsValid()) return;
Gui::coinRemoveAllChildren(GridRoot);
Expand All @@ -268,7 +268,7 @@ void ViewProvider2DObject::updateData(const App::Property* prop)
}
}

void ViewProvider2DObject::onChanged(const App::Property* prop)
void ViewProvider2DObjectGrid::onChanged(const App::Property* prop)
{
// call father
ViewProviderPart::onChanged(prop);
Expand All @@ -279,21 +279,22 @@ void ViewProvider2DObject::onChanged(const App::Property* prop)
else
Gui::coinRemoveAllChildren(GridRoot);
}

if ((prop == &GridSize) || (prop == &GridStyle) || (prop == &TightGrid)) {
if (ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing())) {
createGrid();
}
}
}

void ViewProvider2DObject::Restore(Base::XMLReader &reader)
void ViewProvider2DObjectGrid::Restore(Base::XMLReader &reader)
{
ViewProviderPart::Restore(reader);
}

void ViewProvider2DObject::handleChangedPropertyType(Base::XMLReader &reader,
const char * TypeName,
App::Property * prop)
void ViewProvider2DObjectGrid::handleChangedPropertyType(Base::XMLReader &reader,
const char * TypeName,
App::Property * prop)
{
Base::Type inputType = Base::Type::fromName(TypeName);
if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) &&
Expand All @@ -306,28 +307,56 @@ void ViewProvider2DObject::handleChangedPropertyType(Base::XMLReader &reader,
}
}

void ViewProvider2DObject::attach(App::DocumentObject *pcFeat)
void ViewProvider2DObjectGrid::attach(App::DocumentObject *pcFeat)
{
ViewProviderPart::attach(pcFeat);
ViewProvider2DObject::attach(pcFeat);

if (ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing()))
createGrid();
}

bool ViewProvider2DObject::setEdit(int)
bool ViewProvider2DObjectGrid::setEdit(int)
{
if (ShowGrid.getValue())
createGrid();

return false;
}

void ViewProvider2DObject::unsetEdit(int)
void ViewProvider2DObjectGrid::unsetEdit(int)
{
if (ShowGrid.getValue() && ShowOnlyInEditMode.getValue())
Gui::coinRemoveAllChildren(GridRoot);
}

void ViewProvider2DObjectGrid::updateGridExtent(float minx, float maxx, float miny, float maxy)
{
bool redraw = false;

if (minx < MinX || maxx > MaxX || miny < MinY || maxy > MaxY)
redraw = true;

MinX = minx;
MaxX = maxx;
MinY = miny;
MaxY = maxy;

if (redraw && ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing()))
createGrid();
}

// -----------------------------------------------------------------------

PROPERTY_SOURCE(PartGui::ViewProvider2DObject, PartGui::ViewProviderPart)

ViewProvider2DObject::ViewProvider2DObject()
{
}

ViewProvider2DObject::~ViewProvider2DObject()
{
}

std::vector<std::string> ViewProvider2DObject::getDisplayModes(void) const
{
// get the modes of the father
Expand All @@ -344,27 +373,9 @@ std::vector<std::string> ViewProvider2DObject::getDisplayModes(void) const

const char* ViewProvider2DObject::getDefaultDisplayMode() const
{
return "Wireframe";
}

void ViewProvider2DObject::updateGridExtent(float minx, float maxx, float miny, float maxy)
{
bool redraw = false;

if( minx < MinX || maxx > MaxX || miny < MinY || maxy > MaxY)
redraw = true;

MinX = minx;
MaxX = maxx;
MinY = miny;
MaxY = maxy;

if(redraw && ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing()))
createGrid();
return "Wireframe";
}

// -----------------------------------------------------------------------

namespace Gui {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(PartGui::ViewProvider2DObjectPython, PartGui::ViewProvider2DObject)
Expand Down
17 changes: 14 additions & 3 deletions src/Mod/Part/Gui/ViewProvider2DObject.h
Expand Up @@ -37,7 +37,7 @@ class SoTransform;
namespace PartGui {


class PartGuiExport ViewProvider2DObject: public PartGui::ViewProviderPart
class PartGuiExport ViewProvider2DObject : public PartGui::ViewProviderPart
{
PROPERTY_HEADER(PartGui::ViewProvider2DObject);

Expand All @@ -46,6 +46,19 @@ class PartGuiExport ViewProvider2DObject: public PartGui::ViewProviderPart
ViewProvider2DObject();
/// destructor
virtual ~ViewProvider2DObject();
virtual std::vector<std::string> getDisplayModes(void) const;
virtual const char* getDefaultDisplayMode() const;
};

class PartGuiExport ViewProvider2DObjectGrid : public ViewProvider2DObject
{
PROPERTY_HEADER(PartGui::ViewProvider2DObjectGrid);

public:
/// constructor
ViewProvider2DObjectGrid();
/// destructor
virtual ~ViewProvider2DObjectGrid();

/// Property to switch the grid on and off
App::PropertyBool ShowGrid;
Expand All @@ -59,8 +72,6 @@ class PartGuiExport ViewProvider2DObject: public PartGui::ViewProviderPart

virtual void attach(App::DocumentObject *);
virtual void updateData(const App::Property*);
virtual std::vector<std::string> getDisplayModes(void) const;
virtual const char* getDefaultDisplayMode() const;

/// creates the grid
SoSeparator* createGrid(void);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -281,7 +281,7 @@ const Part::Geometry* GeoById(const std::vector<Part::Geometry*> GeoList, int Id

/* TRANSLATOR SketcherGui::ViewProviderSketch */

PROPERTY_SOURCE(SketcherGui::ViewProviderSketch, PartGui::ViewProvider2DObject)
PROPERTY_SOURCE(SketcherGui::ViewProviderSketch, PartGui::ViewProvider2DObjectGrid)


ViewProviderSketch::ViewProviderSketch()
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Sketcher/Gui/ViewProviderSketch.h
Expand Up @@ -83,7 +83,8 @@ class DrawSketchHandler;
* It uses the class DrawSketchHandler to facilitate the creation
* of new geometry while editing.
*/
class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObject, public Gui::SelectionObserver
class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObjectGrid
, public Gui::SelectionObserver
{
Q_DECLARE_TR_FUNCTIONS(SketcherGui::ViewProviderSketch)
/// generates a warning message about constraint conflicts and appends it to the given message
Expand Down

0 comments on commit da5bd65

Please sign in to comment.