Part: [skip ci] move grid handling from ViewProvider2DObject to ViewProvider2DObjectGrid

This commit is contained in:
wmayer
2020-08-07 16:48:07 +02:00
parent f3dff3bb82
commit 1d9a59e499
5 changed files with 68 additions and 44 deletions

View File

@@ -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();

View File

@@ -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");
@@ -86,7 +86,7 @@ ViewProvider2DObject::ViewProvider2DObject()
sPixmap = "Tree_Part2D";
}
ViewProvider2DObject::~ViewProvider2DObject()
ViewProvider2DObjectGrid::~ViewProvider2DObjectGrid()
{
GridRoot->unref();
}
@@ -94,7 +94,7 @@ ViewProvider2DObject::~ViewProvider2DObject()
// **********************************************************************************
SoSeparator* ViewProvider2DObject::createGrid(void)
SoSeparator* ViewProvider2DObjectGrid::createGrid(void)
{
//double dx = 10 * GridSize.getValue(); // carpet size
//double dy = 10 * GridSize.getValue();
@@ -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);
@@ -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);
@@ -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);
@@ -279,6 +279,7 @@ 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();
@@ -286,14 +287,14 @@ void ViewProvider2DObject::onChanged(const App::Property* prop)
}
}
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()) &&
@@ -306,15 +307,15 @@ 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();
@@ -322,12 +323,40 @@ bool ViewProvider2DObject::setEdit(int)
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
@@ -344,27 +373,9 @@ std::vector<std::string> ViewProvider2DObject::getDisplayModes(void) const
const char* ViewProvider2DObject::getDefaultDisplayMode() const
{
return "Wireframe";
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 {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(PartGui::ViewProvider2DObjectPython, PartGui::ViewProvider2DObject)

View File

@@ -37,7 +37,7 @@ class SoTransform;
namespace PartGui {
class PartGuiExport ViewProvider2DObject: public PartGui::ViewProviderPart
class PartGuiExport ViewProvider2DObject : public PartGui::ViewProviderPart
{
PROPERTY_HEADER(PartGui::ViewProvider2DObject);
@@ -46,6 +46,19 @@ public:
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;
@@ -59,8 +72,6 @@ public:
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);

View File

@@ -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()

View File

@@ -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