Part: Gui ViewProvider2D Grid Management

========================================

1. The Grid has a default maximum of 10000 lines that is controlled via a new property. The grid is not created (is empty)
if a higher number of lines is necessary. This event is show as a Warning in the Report view.

2. The Grid now checks a new property ShowOnlyInEditMode before deciding whether to show the grid or not. This is a new
mode for ViewProvider2D and derived objects. If the property is set to true (and showGrid is true), the grid is only shown
if the object is in edit mode. If the property is set to false, the grid is shown regardless of whether it is in edit mode
or not (provided that showGrid is true).

3. Grid limits are now encapsulated (private). They can be set via a new function updateGridExtent.
This commit is contained in:
Abdullah Tahiri
2020-05-27 16:47:21 +02:00
committed by abdullahtahiriyo
parent da33ffc062
commit 1efe9c9208
2 changed files with 47 additions and 10 deletions

View File

@@ -65,10 +65,12 @@ PROPERTY_SOURCE(PartGui::ViewProvider2DObject, PartGui::ViewProviderPart)
ViewProvider2DObject::ViewProvider2DObject()
{
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(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(maxNumberOfLines,(10000),"Grid",(App::PropertyType)(App::Prop_None),"Maximum Number of Lines in grid");
GridRoot = new SoAnnotation();
GridRoot->ref();
@@ -199,6 +201,13 @@ SoSeparator* ViewProvider2DObject::createGrid(void)
int lines = vlines + hlines;
if( lines > maxNumberOfLines.getValue() ) { // If
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);
return GridRoot;
}
// set the grid indices
grid->numVertices.setNum(lines);
int32_t* vertices = grid->numVertices.startEditing();
@@ -247,9 +256,12 @@ void ViewProvider2DObject::updateData(const App::Property* prop)
this->MaxX = bbox2d.MaxX;
this->MinY = bbox2d.MinY;
this->MaxY = bbox2d.MaxY;
if (ShowGrid.getValue()) {
if (ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing()) ) {
createGrid();
}
else {
Gui::coinRemoveAllChildren(GridRoot);
}
}
}
@@ -258,15 +270,14 @@ void ViewProvider2DObject::onChanged(const App::Property* prop)
// call father
ViewProviderPart::onChanged(prop);
if (prop == &ShowGrid || prop == &Visibility) {
if (ShowGrid.getValue() && Visibility.getValue())
if (prop == &ShowGrid || prop == &ShowOnlyInEditMode || prop == &Visibility) {
if (ShowGrid.getValue() && Visibility.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing()))
createGrid();
else
Gui::coinRemoveAllChildren(GridRoot);
}
if ((prop == &GridSize) || (prop == &GridStyle) || (prop == &TightGrid)) {
if (ShowGrid.getValue()) {
Gui::coinRemoveAllChildren(GridRoot);
if (ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing())) {
createGrid();
}
}
@@ -296,18 +307,22 @@ void ViewProvider2DObject::attach(App::DocumentObject *pcFeat)
{
ViewProviderPart::attach(pcFeat);
if (ShowGrid.getValue())
if (ShowGrid.getValue() && !(ShowOnlyInEditMode.getValue() && !this->isEditing()))
createGrid();
}
bool ViewProvider2DObject::setEdit(int)
{
if (ShowGrid.getValue())
createGrid();
return false;
}
void ViewProvider2DObject::unsetEdit(int)
{
if (ShowGrid.getValue() && ShowOnlyInEditMode.getValue())
Gui::coinRemoveAllChildren(GridRoot);
}
std::vector<std::string> ViewProvider2DObject::getDisplayModes(void) const
@@ -329,6 +344,22 @@ 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();
}
// -----------------------------------------------------------------------
namespace Gui {

View File

@@ -49,10 +49,12 @@ public:
/// Property to switch the grid on and off
App::PropertyBool ShowGrid;
App::PropertyBool ShowOnlyInEditMode;
App::PropertyLength GridSize;
App::PropertyEnumeration GridStyle;
App::PropertyBool TightGrid;
App::PropertyBool GridSnap;
App::PropertyInteger maxNumberOfLines;
virtual void attach(App::DocumentObject *);
virtual void updateData(const App::Property*);
@@ -60,7 +62,7 @@ public:
virtual const char* getDefaultDisplayMode() const;
/// creates the grid
SoSeparator* createGrid(void);
SoSeparator* createGrid(void);
protected:
virtual bool setEdit(int ModNum);
@@ -72,12 +74,16 @@ protected:
SoSeparator *GridRoot;
void updateGridExtent(float minx, float maxx, float miny, float maxy);
static const char* GridStyleEnums[];
static App::PropertyQuantityConstraint::Constraints GridSizeRange;
private:
float MinX;
float MaxX;
float MinY;
float MaxY;
static const char* GridStyleEnums[];
static App::PropertyQuantityConstraint::Constraints GridSizeRange;
};
typedef Gui::ViewProviderPythonFeatureT<ViewProvider2DObject> ViewProvider2DObjectPython;