Improve handling of broken references (changed Edge/Vertex names)
This commit is contained in:
parent
afa8c9fece
commit
54fed5ccfb
|
@ -119,6 +119,7 @@ DrawViewDimension::DrawViewDimension(void)
|
|||
Rotation.setStatus(App::Property::Hidden,true);
|
||||
|
||||
measurement = new Measure::Measurement();
|
||||
//TODO: should have better initial datumLabel position than (0,0) in the DVP?? something closer to the object being measured?
|
||||
}
|
||||
|
||||
DrawViewDimension::~DrawViewDimension()
|
||||
|
@ -131,16 +132,12 @@ void DrawViewDimension::onChanged(const App::Property* prop)
|
|||
{
|
||||
if (!isRestoring()) {
|
||||
if (prop == &MeasureType) {
|
||||
// Base::Console().Message("TRACE -DVD::onChanged(MeasureType) - MeasureType: %d Measurehas3D: %d thisHas3D: %d\n",
|
||||
// MeasureType.getValue(),measurement->has3DReferences(),has3DReferences());
|
||||
if (MeasureType.isValue("True") && !measurement->has3DReferences()) {
|
||||
Base::Console().Warning("Dimension %s missing Reference to 3D model. Must be Projected.\n", getNameInDocument());
|
||||
MeasureType.setValue("Projected");
|
||||
}
|
||||
}
|
||||
if (prop == &References3D) { //have to rebuild the Measurement object
|
||||
// Base::Console().Message("TRACE -DVD::onChanged(References3D) - MeasureType: %d has3D: %d thisHas3D: %d\n",
|
||||
// MeasureType.getValue(),measurement->has3DReferences(),has3DReferences());
|
||||
clear3DMeasurements(); //Measurement object
|
||||
if (!(References3D.getValues()).empty()) {
|
||||
setAll3DMeasurement();
|
||||
|
@ -189,7 +186,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
|
|||
return App::DocumentObject::execute();;
|
||||
}
|
||||
|
||||
std::string DrawViewDimension::getFormatedValue() const
|
||||
std::string DrawViewDimension::getFormatedValue()
|
||||
{
|
||||
QString str = QString::fromUtf8(FormatSpec.getStrValue().data(),FormatSpec.getStrValue().size());
|
||||
double val = std::abs(getDimValue());
|
||||
|
@ -230,16 +227,16 @@ std::string DrawViewDimension::getFormatedValue() const
|
|||
}
|
||||
|
||||
|
||||
double DrawViewDimension::getDimValue() const
|
||||
double DrawViewDimension::getDimValue()
|
||||
{
|
||||
double result = 0.0;
|
||||
if (!has2DReferences()) { //happens during Dimension creation
|
||||
Base::Console().Message("INFO - DVD::getDimValue - Dimension has no References\n");
|
||||
Base::Console().Log("INFO - DVD::getDimValue - Dimension has no References\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!getViewPart()->hasGeometry()) { //happens when loading saved document
|
||||
Base::Console().Message("INFO - DVD::getDimValue ViewPart has no Geometry yet\n");
|
||||
Base::Console().Log("INFO - DVD::getDimValue ViewPart has no Geometry yet\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -275,7 +272,8 @@ double DrawViewDimension::getDimValue() const
|
|||
const std::vector<std::string> &subElements = References2D.getSubValues();
|
||||
|
||||
if (!checkReferences2D()) {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
if ( Type.isValue("Distance") ||
|
||||
|
@ -289,7 +287,8 @@ double DrawViewDimension::getDimValue() const
|
|||
if (geom && geom->geomType == TechDrawGeometry::GeomType::GENERIC) {
|
||||
gen = static_cast<TechDrawGeometry::Generic*>(geom);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
Base::Vector2d start = gen->points[0];
|
||||
|
@ -311,7 +310,8 @@ double DrawViewDimension::getDimValue() const
|
|||
if (geom0 && geom0->geomType == TechDrawGeometry::GeomType::GENERIC) {
|
||||
gen0 = static_cast<TechDrawGeometry::Generic*>(geom0);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
TechDrawGeometry::BaseGeom* geom1 = getViewPart()->getProjEdgeByIndex(idx1);
|
||||
|
@ -319,7 +319,8 @@ double DrawViewDimension::getDimValue() const
|
|||
if (geom1 && geom1->geomType == TechDrawGeometry::GeomType::GENERIC) {
|
||||
gen1 = static_cast<TechDrawGeometry::Generic*>(geom1);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
Base::Vector2d s0 = gen0->points[0];
|
||||
|
@ -345,9 +346,10 @@ double DrawViewDimension::getDimValue() const
|
|||
if ((v0 == nullptr) ||
|
||||
(v1 == nullptr) ) {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
Base::Vector2d start = v0->pnt;
|
||||
Base::Vector2d start = v0->pnt; //v0 != nullptr, but v0->pnt is invalid
|
||||
Base::Vector2d end = v1->pnt;
|
||||
Base::Vector2d line = end - start;
|
||||
if (Type.isValue("Distance")) {
|
||||
|
@ -371,7 +373,8 @@ double DrawViewDimension::getDimValue() const
|
|||
}
|
||||
if ((v == nullptr) ||
|
||||
(e == nullptr) ) {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
Base::Vector2d nearPoint = e->nearPoint(v->pnt);
|
||||
|
@ -393,7 +396,8 @@ double DrawViewDimension::getDimValue() const
|
|||
(base && base->geomType == TechDrawGeometry::GeomType::ARCOFCIRCLE)) {
|
||||
circle = static_cast<TechDrawGeometry::Circle*> (base);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
result = circle->radius / getViewPart()->Scale.getValue(); //Projected BaseGeom is scaled for drawing
|
||||
|
@ -415,20 +419,17 @@ double DrawViewDimension::getDimValue() const
|
|||
//Relcalculate the measurement based on references stored.
|
||||
//WF: why not use projected geom in GeomObject and Vector2d.GetAngle? intersection pt & direction issues?
|
||||
//TODO: do we need to distinguish inner vs outer angle? -wf
|
||||
// if(subElements.size() != 2) {
|
||||
// throw Base::Exception("FVD - Two references required for angle measurement");
|
||||
// }
|
||||
if (getRefType() != twoEdge) {
|
||||
// throw Base::Exception("DVD - Two edge references required for angle measurement");
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(subElements[1]);
|
||||
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(objects[0]) );
|
||||
if( viewPart == nullptr ) {
|
||||
Base::Console().Message("INFO - DVD::getDimValue - References2D not DrawViewPart\n");
|
||||
return 0.0;
|
||||
Base::Console().Log("INFO - DVD::getDimValue - References2D not DrawViewPart\n");
|
||||
return result;
|
||||
}
|
||||
TechDrawGeometry::BaseGeom* edge0 = viewPart->getProjEdgeByIndex(idx0);
|
||||
TechDrawGeometry::BaseGeom* edge1 = viewPart->getProjEdgeByIndex(idx1);
|
||||
|
@ -437,13 +438,15 @@ double DrawViewDimension::getDimValue() const
|
|||
if (edge0 && edge0->geomType == TechDrawGeometry::GeomType::GENERIC) {
|
||||
gen1 = static_cast<TechDrawGeometry::Generic*>(edge0);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
if (edge1 && edge1->geomType == TechDrawGeometry::GeomType::GENERIC) {
|
||||
gen2 = static_cast<TechDrawGeometry::Generic*>(edge1);
|
||||
} else {
|
||||
Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
Base::Console().Log("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
|
||||
References2D.setValue(nullptr,"");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -618,7 +621,7 @@ double DrawViewDimension::dist2Segs(Base::Vector2d s1,
|
|||
|
||||
BRepExtrema_DistShapeShape extss(edge1, edge2);
|
||||
if (!extss.IsDone()) {
|
||||
throw Base::Exception("FVD - BRepExtrema_DistShapeShape failed");
|
||||
throw Base::Exception("DVD - BRepExtrema_DistShapeShape failed");
|
||||
}
|
||||
int count = extss.NbSolution();
|
||||
double minDist = 0.0;
|
||||
|
@ -631,7 +634,18 @@ double DrawViewDimension::dist2Segs(Base::Vector2d s1,
|
|||
|
||||
bool DrawViewDimension::has2DReferences(void) const
|
||||
{
|
||||
return (References2D.getSize() > 0);
|
||||
bool result = false;
|
||||
const std::vector<App::DocumentObject*> &objects = References2D.getValues();
|
||||
const std::vector<std::string> &SubNames = References2D.getSubValues();
|
||||
if (!objects.empty()) {
|
||||
App::DocumentObject* testRef = objects.at(0);
|
||||
if (testRef != nullptr) {
|
||||
if (!SubNames.empty()) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DrawViewDimension::has3DReferences(void) const
|
||||
|
|
|
@ -65,9 +65,6 @@ public:
|
|||
App::PropertyFloat LineWidth;
|
||||
//App::PropertyBool CentreLines;
|
||||
|
||||
//TODO: do we need a property for the actual dimension value? how else to access from Py?
|
||||
//wf: expose getValue & getFormatedValue
|
||||
|
||||
short mustExecute() const;
|
||||
bool has2DReferences(void) const;
|
||||
bool has3DReferences(void) const;
|
||||
|
@ -85,8 +82,8 @@ public:
|
|||
//return PyObject as DrawViewDimensionPy
|
||||
virtual PyObject *getPyObject(void);
|
||||
|
||||
virtual std::string getFormatedValue() const;
|
||||
virtual double getDimValue() const;
|
||||
virtual std::string getFormatedValue();
|
||||
virtual double getDimValue();
|
||||
DrawViewPart* getViewPart() const;
|
||||
virtual QRectF getRect() const { return QRectF(0,0,1,1);} //pretend dimensions always fit!
|
||||
static int getRefType1(const std::string s);
|
||||
|
@ -99,7 +96,6 @@ public:
|
|||
protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
virtual void onDocumentRestored();
|
||||
// int getIndexFromName(std::string geomName) const; //obs? replaced by DrawUtil??
|
||||
bool showUnits() const;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue
Block a user