Change Scale to PropertyFloatConstaint to prevent OCC loop when Scale == 0
This commit is contained in:
committed by
Yorik van Havre
parent
d5bb03b75f
commit
79a5a6adde
@@ -26,6 +26,8 @@
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <Standard_Failure.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <cmath>
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,6 +37,7 @@
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include "DrawView.h"
|
||||
#include "DrawPage.h"
|
||||
@@ -57,6 +60,10 @@ const char* DrawView::ScaleTypeEnums[]= {"Page",
|
||||
"Automatic",
|
||||
"Custom",
|
||||
NULL};
|
||||
App::PropertyFloatConstraint::Constraints DrawView::scaleRange = {Precision::Confusion(),
|
||||
std::numeric_limits<double>::max(),
|
||||
pow(10,- Base::UnitsApi::getDecimals())};
|
||||
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawView, App::DocumentObject)
|
||||
|
||||
@@ -74,6 +81,7 @@ DrawView::DrawView(void)
|
||||
ScaleType.setEnums(ScaleTypeEnums);
|
||||
ADD_PROPERTY_TYPE(ScaleType,((long)0),group, App::Prop_None, "Scale Type");
|
||||
ADD_PROPERTY_TYPE(Scale ,(1.0),group,App::Prop_None,"Scale factor of the view");
|
||||
Scale.setConstraints(&scaleRange);
|
||||
|
||||
ADD_PROPERTY_TYPE(KeepLabel ,(false),fgroup,App::Prop_None,"Keep Label on Page even if toggled off");
|
||||
ADD_PROPERTY_TYPE(Caption ,(""),fgroup,App::Prop_None,"Short text about the view");
|
||||
@@ -234,6 +242,71 @@ void DrawView::setPosition(double x, double y)
|
||||
//recompute.unlock()
|
||||
}
|
||||
|
||||
void DrawView::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* schemaProp = getPropertyByName(PropName);
|
||||
try {
|
||||
if(schemaProp){
|
||||
if (strcmp(schemaProp->getTypeId().getName(), TypeName) == 0){ //if the property type in obj == type in schema
|
||||
schemaProp->Restore(reader); //nothing special to do
|
||||
} else {
|
||||
if (strcmp(PropName, "Scale") == 0) {
|
||||
if (schemaProp->isDerivedFrom(App::PropertyFloatConstraint::getClassTypeId())){ //right property type
|
||||
schemaProp->Restore(reader); //nothing special to do
|
||||
} else { //Scale, but not PropertyFloatConstraint
|
||||
App::PropertyFloat tmp;
|
||||
if (strcmp(tmp.getTypeId().getName(),TypeName)) { //property in file is Float
|
||||
tmp.setContainer(this);
|
||||
tmp.Restore(reader);
|
||||
double tmpValue = tmp.getValue();
|
||||
if (tmpValue > 0.0) {
|
||||
static_cast<App::PropertyFloatConstraint*>(schemaProp)->setValue(tmpValue);
|
||||
} else {
|
||||
static_cast<App::PropertyFloatConstraint*>(schemaProp)->setValue(1.0);
|
||||
}
|
||||
} else {
|
||||
// has Scale prop that isn't Float!
|
||||
Base::Console().Log("DrawView::Restore - old Document Scale is Not Float!\n");
|
||||
// no idea
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Base::Console().Log("DrawView::Restore - old Document has unknown Property\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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("PropertyContainer::Restore: Unknown C++ exception thrown");
|
||||
}
|
||||
#endif
|
||||
|
||||
reader.readEndElement("Property");
|
||||
}
|
||||
reader.readEndElement("Properties");
|
||||
}
|
||||
|
||||
|
||||
PyObject *DrawView::getPyObject(void)
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
|
||||
Reference in New Issue
Block a user