Change Scale to PropertyFloatConstaint to prevent OCC loop when Scale == 0
This commit is contained in:
parent
d5bb03b75f
commit
79a5a6adde
|
@ -52,6 +52,10 @@
|
|||
#include <TopTools.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
#include <TopExp.hxx>
|
||||
#include <Precision.hxx>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
|
@ -59,6 +63,7 @@
|
|||
#include <Base/Exception.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include "HatchLine.h"
|
||||
#include "DrawUtil.h"
|
||||
|
@ -73,6 +78,10 @@ using namespace TechDraw;
|
|||
using namespace TechDrawGeometry;
|
||||
using namespace std;
|
||||
|
||||
App::PropertyFloatConstraint::Constraints DrawGeomHatch::scaleRange = {Precision::Confusion(),
|
||||
std::numeric_limits<double>::max(),
|
||||
pow(10,- Base::UnitsApi::getDecimals())};
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawGeomHatch, App::DocumentObject)
|
||||
|
||||
|
||||
|
@ -84,6 +93,7 @@ DrawGeomHatch::DrawGeomHatch(void)
|
|||
ADD_PROPERTY_TYPE(FilePattern ,(""),vgroup,App::Prop_None,"The crosshatch pattern file for this area");
|
||||
ADD_PROPERTY_TYPE(NamePattern,(""),vgroup,App::Prop_None,"The name of the pattern");
|
||||
ADD_PROPERTY_TYPE(ScalePattern,(1.0),vgroup,App::Prop_None,"GeomHatch pattern size adjustment");
|
||||
ScalePattern.setConstraints(&scaleRange);
|
||||
|
||||
getParameters();
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
App::PropertyLinkSub Source; //the dvX & face(s) this crosshatch belongs to
|
||||
App::PropertyFile FilePattern;
|
||||
App::PropertyString NamePattern;
|
||||
App::PropertyFloat ScalePattern;
|
||||
App::PropertyFloatConstraint ScalePattern;
|
||||
|
||||
virtual short mustExecute() const;
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
|
@ -79,6 +79,8 @@ protected:
|
|||
std::vector<LineSet> m_lineSets;
|
||||
|
||||
private:
|
||||
static App::PropertyFloatConstraint::Constraints scaleRange;
|
||||
|
||||
};
|
||||
|
||||
typedef App::FeaturePythonT<DrawGeomHatch> DrawGeomHatchPython;
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#include <Precision.hxx>
|
||||
#include <cmath>
|
||||
|
||||
#endif
|
||||
|
||||
#include <iomanip>
|
||||
|
@ -37,6 +40,7 @@
|
|||
#include <Base/Exception.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include "DrawViewPart.h"
|
||||
#include "DrawHatch.h"
|
||||
|
@ -46,6 +50,10 @@
|
|||
using namespace TechDraw;
|
||||
using namespace std;
|
||||
|
||||
App::PropertyFloatConstraint::Constraints DrawHatch::scaleRange = {Precision::Confusion(),
|
||||
std::numeric_limits<double>::max(),
|
||||
pow(10,- Base::UnitsApi::getDecimals())};
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawHatch, App::DocumentObject)
|
||||
|
||||
|
||||
|
@ -62,6 +70,7 @@ DrawHatch::DrawHatch(void)
|
|||
ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area");
|
||||
ADD_PROPERTY_TYPE(HatchColor,(fcColor),vgroup,App::Prop_None,"The color of the hatch pattern");
|
||||
ADD_PROPERTY_TYPE(HatchScale,(1.0),vgroup,App::Prop_None,"Hatch pattern size adjustment");
|
||||
HatchScale.setConstraints(&scaleRange);
|
||||
DirProjection.setStatus(App::Property::ReadOnly,true);
|
||||
|
||||
hGrp = App::GetApplication().GetUserParameter()
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
App::PropertyLinkSub Source; //the dvp & face this hatch belongs to
|
||||
App::PropertyFile HatchPattern;
|
||||
App::PropertyColor HatchColor;
|
||||
App::PropertyFloat HatchScale;
|
||||
App::PropertyFloatConstraint HatchScale;
|
||||
|
||||
//short mustExecute() const;
|
||||
|
||||
|
@ -62,6 +62,8 @@ protected:
|
|||
void onChanged(const App::Property* prop);
|
||||
|
||||
private:
|
||||
static App::PropertyFloatConstraint::Constraints scaleRange;
|
||||
|
||||
};
|
||||
|
||||
typedef App::FeaturePythonT<DrawHatch> DrawHatchPython;
|
||||
|
|
|
@ -27,12 +27,15 @@
|
|||
# include <sstream>
|
||||
# include <iostream>
|
||||
# include <iterator>
|
||||
#include <Precision.hxx>
|
||||
#include <cmath>
|
||||
#endif
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
|
@ -57,6 +60,10 @@ using namespace std;
|
|||
// DrawPage
|
||||
//===========================================================================
|
||||
|
||||
App::PropertyFloatConstraint::Constraints DrawPage::scaleRange = {Precision::Confusion(),
|
||||
std::numeric_limits<double>::max(),
|
||||
pow(10,- Base::UnitsApi::getDecimals())};
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawPage, App::DocumentObject)
|
||||
|
||||
const char* DrawPage::ProjectionTypeEnums[] = { "First Angle",
|
||||
|
@ -87,7 +94,7 @@ DrawPage::DrawPage(void)
|
|||
}
|
||||
|
||||
ADD_PROPERTY_TYPE(Scale, (1.0), group, App::Prop_None, "Scale factor for this Page");
|
||||
//TODO: Page should create itself with default Template instead of Cmd figuring it out?
|
||||
Scale.setConstraints(&scaleRange);
|
||||
}
|
||||
|
||||
DrawPage::~DrawPage()
|
||||
|
@ -328,9 +335,75 @@ void DrawPage::unsetupObject()
|
|||
}
|
||||
Views.setValues(emptyViews);
|
||||
|
||||
//no template crash here?? if Template.getValue is null or invalid, this will fail.
|
||||
std::string templateName = Template.getValue()->getNameInDocument();
|
||||
Base::Interpreter().runStringArg("App.getDocument(\"%s\").removeObject(\"%s\")",
|
||||
docName.c_str(), templateName.c_str());
|
||||
Template.setValue(nullptr);
|
||||
}
|
||||
|
||||
void DrawPage::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("DrawPage::Restore - old Document Scale is Not Float!\n");
|
||||
// no idea
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Base::Console().Log("DrawPage::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");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
App::PropertyLinkList Views;
|
||||
App::PropertyLink Template;
|
||||
|
||||
App::PropertyFloat Scale;
|
||||
App::PropertyFloatConstraint Scale;
|
||||
App::PropertyEnumeration ProjectionType; // First or Third Angle
|
||||
|
||||
/** @name methods overide Feature */
|
||||
|
@ -51,6 +51,7 @@ public:
|
|||
/// recalculate the Feature
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
//@}
|
||||
void Restore(Base::XMLReader &reader);
|
||||
|
||||
int addView(App::DocumentObject *docObj);
|
||||
int removeView(App::DocumentObject* docObj);
|
||||
|
@ -94,6 +95,7 @@ protected:
|
|||
private:
|
||||
static const char* ProjectionTypeEnums[];
|
||||
bool nowDeleting;
|
||||
static App::PropertyFloatConstraint::Constraints scaleRange;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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())) {
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
App::PropertyFloat X;
|
||||
App::PropertyFloat Y;
|
||||
App::PropertyFloat Scale;
|
||||
App::PropertyFloatConstraint Scale;
|
||||
|
||||
App::PropertyEnumeration ScaleType;
|
||||
App::PropertyFloat Rotation;
|
||||
|
@ -62,6 +62,7 @@ public:
|
|||
virtual void onDocumentRestored();
|
||||
virtual short mustExecute() const;
|
||||
//@}
|
||||
void Restore(Base::XMLReader &reader);
|
||||
|
||||
bool isInClip();
|
||||
|
||||
|
@ -90,6 +91,7 @@ protected:
|
|||
|
||||
private:
|
||||
static const char* ScaleTypeEnums[];
|
||||
static App::PropertyFloatConstraint::Constraints scaleRange;
|
||||
};
|
||||
|
||||
typedef App::FeaturePythonT<DrawView> DrawViewPython;
|
||||
|
|
Loading…
Reference in New Issue
Block a user