+ prepare ViewProvider2DObject to read in GridSize from old projects
This commit is contained in:
parent
f124f6e70b
commit
d0e52d3578
|
@ -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>
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
/// 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;
|
||||
/// 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;
|
||||
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);
|
||||
/// 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);
|
||||
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;
|
||||
SoSeparator *GridRoot;
|
||||
|
||||
float MinX;
|
||||
float MaxX;
|
||||
float MinY;
|
||||
float MaxY;
|
||||
static const char* GridStyleEnums[];
|
||||
static App::PropertyQuantityConstraint::Constraints GridSizeRange;
|
||||
float MinX;
|
||||
float MaxX;
|
||||
float MinY;
|
||||
float MaxY;
|
||||
static const char* GridStyleEnums[];
|
||||
static App::PropertyQuantityConstraint::Constraints GridSizeRange;
|
||||
};
|
||||
|
||||
typedef Gui::ViewProviderPythonFeatureT<ViewProvider2DObject> ViewProvider2DObjectPython;
|
||||
|
|
Loading…
Reference in New Issue
Block a user