Skip to content

Commit

Permalink
+ prepare ViewProvider2DObject to read in GridSize from old projects
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 11, 2016
1 parent f124f6e commit d0e52d3
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 33 deletions.
52 changes: 52 additions & 0 deletions src/Mod/Part/Gui/ViewProvider2DObject.cpp
Expand Up @@ -36,7 +36,9 @@
#endif

/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Base/Reader.h>
#include <Base/ViewProj.h>
#include <App/Application.h>
#include <Gui/SoFCBoundingBox.h>
Expand Down Expand Up @@ -232,6 +234,56 @@ void ViewProvider2DObject::onChanged(const App::Property* prop)
}
}

void ViewProvider2DObject::Restore(Base::XMLReader &reader)
{
reader.readElement("Properties");
int Cnt = reader.getAttributeAsInteger("Count");

for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Property");
const char* PropName = reader.getAttribute("name");
const char* TypeName = reader.getAttribute("type");
App::Property* prop = getPropertyByName(PropName);

try {
if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) {
prop->Restore(reader);
}
else if (prop) {
Base::Type inputType = Base::Type::fromName(TypeName);
if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) &&
inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
// Do not directly call the property's Restore method in case the implmentation
// has changed. So, create a temporary PropertyFloat object and assign the value.
App::PropertyFloat floatProp;
floatProp.Restore(reader);
static_cast<App::PropertyFloat*>(prop)->setValue(floatProp.getValue());
}
}
}
catch (const Base::XMLParseException&) {
throw; // re-throw
}
catch (const Base::Exception &e) {
Base::Console().Error("%s\n", e.what());
}
catch (const std::exception &e) {
Base::Console().Error("%s\n", e.what());
}
catch (const char* e) {
Base::Console().Error("%s\n", e);
}
#ifndef FC_DEBUG
catch (...) {
Base::Console().Error("Primitive::Restore: Unknown C++ exception thrown");
}
#endif

reader.readEndElement("Property");
}
reader.readEndElement("Properties");
}

void ViewProvider2DObject::attach(App::DocumentObject *pcFeat)
{
ViewProviderPart::attach(pcFeat);
Expand Down
67 changes: 34 additions & 33 deletions src/Mod/Part/Gui/ViewProvider2DObject.h
Expand Up @@ -39,43 +39,44 @@ namespace PartGui {

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

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

/// Property to switch the grid on and off
App::PropertyBool ShowGrid;
App::PropertyLength GridSize;
App::PropertyEnumeration GridStyle;
App::PropertyBool TightGrid;
App::PropertyBool GridSnap;

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);
/// constructor
ViewProvider2DObject();
/// destructor
virtual ~ViewProvider2DObject();

/// Property to switch the grid on and off
App::PropertyBool ShowGrid;
App::PropertyLength GridSize;
App::PropertyEnumeration GridStyle;
App::PropertyBool TightGrid;
App::PropertyBool GridSnap;

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

protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
/// get called by the container whenever a property has been changed
virtual void onChanged(const App::Property* prop);

SoSeparator *GridRoot;

float MinX;
float MaxX;
float MinY;
float MaxY;
static const char* GridStyleEnums[];
static App::PropertyQuantityConstraint::Constraints GridSizeRange;
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
/// get called by the container whenever a property has been changed
virtual void onChanged(const App::Property* prop);
virtual void Restore(Base::XMLReader &reader);

SoSeparator *GridRoot;

float MinX;
float MaxX;
float MinY;
float MaxY;
static const char* GridStyleEnums[];
static App::PropertyQuantityConstraint::Constraints GridSizeRange;
};

typedef Gui::ViewProviderPythonFeatureT<ViewProvider2DObject> ViewProvider2DObjectPython;
Expand Down

0 comments on commit d0e52d3

Please sign in to comment.