From cd6bf982e7dc443e050e4d93b4954951daebcf15 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 18 Feb 2016 16:22:09 +0300 Subject: [PATCH] empty AIS presentation should not be visualized in the viewer. It is caused by OCCT crash, which may happens on Linux platform sometimes in this case. The crash is #968. --- .../SketchPlugin_ConstraintAngle.cpp | 6 +- .../SketchPlugin_ConstraintCoincidence.cpp | 6 +- .../SketchPlugin_ConstraintCollinear.cpp | 9 +- .../SketchPlugin_ConstraintDistance.cpp | 6 +- .../SketchPlugin_ConstraintEqual.cpp | 6 +- .../SketchPlugin_ConstraintHorizontal.cpp | 19 +--- .../SketchPlugin_ConstraintLength.cpp | 6 +- .../SketchPlugin_ConstraintMiddle.cpp | 9 +- .../SketchPlugin_ConstraintMirror.cpp | 6 +- .../SketchPlugin_ConstraintParallel.cpp | 6 +- .../SketchPlugin_ConstraintPerpendicular.cpp | 6 +- .../SketchPlugin_ConstraintRadius.cpp | 6 +- .../SketchPlugin_ConstraintRigid.cpp | 28 +++--- .../SketchPlugin_ConstraintTangent.cpp | 6 +- .../SketchPlugin_ConstraintVertical.cpp | 6 +- .../SketchPlugin_MultiRotation.cpp | 6 +- .../SketchPlugin_MultiTranslation.cpp | 6 +- src/SketcherPrs/SketcherPrs_Angle.cpp | 57 ++++++++---- src/SketcherPrs/SketcherPrs_Angle.h | 7 ++ src/SketcherPrs/SketcherPrs_Coincident.cpp | 23 ++++- src/SketcherPrs/SketcherPrs_Coincident.h | 9 +- src/SketcherPrs/SketcherPrs_Equal.cpp | 24 ++++- src/SketcherPrs/SketcherPrs_Equal.h | 7 ++ src/SketcherPrs/SketcherPrs_Factory.cpp | 92 +++++++++++++------ src/SketcherPrs/SketcherPrs_Factory.h | 4 +- src/SketcherPrs/SketcherPrs_HVDirection.cpp | 16 +++- src/SketcherPrs/SketcherPrs_HVDirection.h | 8 ++ .../SketcherPrs_LengthDimension.cpp | 41 ++++++--- src/SketcherPrs/SketcherPrs_LengthDimension.h | 11 ++- src/SketcherPrs/SketcherPrs_Mirror.cpp | 37 ++++++-- src/SketcherPrs/SketcherPrs_Mirror.h | 7 ++ src/SketcherPrs/SketcherPrs_Parallel.cpp | 19 +++- src/SketcherPrs/SketcherPrs_Parallel.h | 8 ++ src/SketcherPrs/SketcherPrs_Perpendicular.cpp | 19 +++- src/SketcherPrs/SketcherPrs_Perpendicular.h | 7 ++ src/SketcherPrs/SketcherPrs_Radius.cpp | 75 ++++++++++++--- src/SketcherPrs/SketcherPrs_Radius.h | 7 ++ src/SketcherPrs/SketcherPrs_Rigid.cpp | 31 ++++++- src/SketcherPrs/SketcherPrs_Rigid.h | 7 ++ src/SketcherPrs/SketcherPrs_Tangent.cpp | 18 +++- src/SketcherPrs/SketcherPrs_Tangent.h | 7 ++ .../SketcherPrs_Transformation.cpp | 22 ++++- src/SketcherPrs/SketcherPrs_Transformation.h | 7 ++ 43 files changed, 513 insertions(+), 200 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 646e4b800..ef711f6a5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -78,10 +78,8 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp index b1fb8be97..ed4095908 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp @@ -45,10 +45,8 @@ AISObjectPtr SketchPlugin_ConstraintCoincidence::getAISObject(AISObjectPtr thePr if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp index 75da202f1..d7c7e07c3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp @@ -25,11 +25,10 @@ AISObjectPtr SketchPlugin_ConstraintCollinear::getAISObject(AISObjectPtr thePrev if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - // TODO - //anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS; + // TODO + //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(), + // thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 583477a02..ea131563f 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -138,10 +138,8 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp b/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp index 1b80c0c6b..e63764802 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp @@ -36,10 +36,8 @@ AISObjectPtr SketchPlugin_ConstraintEqual::getAISObject(AISObjectPtr thePrevious if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::equalConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::equalConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp index 0f7aa2492..558b44a3d 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp @@ -36,23 +36,8 @@ AISObjectPtr SketchPlugin_ConstraintHorizontal::getAISObject(AISObjectPtr thePre if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - - if (!anAIS) { - anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane()); - /* - ObjectPtr aObj = SketcherPrs_Tools::getResult(this, SketchPlugin_Constraint::ENTITY_A()); - if (SketcherPrs_Tools::getShape(aObj).get() != NULL) { - anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane()); - }*/ - } - /*else { - ObjectPtr aObj = SketcherPrs_Tools::getResult(this, SketchPlugin_Constraint::ENTITY_A()); - if (SketcherPrs_Tools::getShape(aObj).get() == NULL) { - anAIS = AISObjectPtr(); - } - }*/ + AISObjectPtr anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } - diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index e97b82141..949908b29 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -132,10 +132,8 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp index 76e8509cb..7112d4401 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp @@ -25,11 +25,10 @@ AISObjectPtr SketchPlugin_ConstraintMiddle::getAISObject(AISObjectPtr thePreviou if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - // TODO - //anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS; + // TODO + //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(), + // thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index 4b3bbb997..e17a704c5 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -188,10 +188,8 @@ AISObjectPtr SketchPlugin_ConstraintMirror::getAISObject(AISObjectPtr thePreviou if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp index 42ce74b78..7a6f71af5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp @@ -43,10 +43,8 @@ AISObjectPtr SketchPlugin_ConstraintParallel::getAISObject(AISObjectPtr thePrevi if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index eb9ec92f5..c7e327fa1 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -41,10 +41,8 @@ AISObjectPtr SketchPlugin_ConstraintPerpendicular::getAISObject(AISObjectPtr the if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::perpendicularConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::perpendicularConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index e9ce8ae6a..f4bf1708f 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -152,10 +152,8 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp index 8867e16d5..418c0dd53 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp @@ -35,19 +35,23 @@ AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious return thePrevious; AISObjectPtr anAIS = thePrevious; - if (anAIS.get() == NULL) { - std::shared_ptr aData = data(); - std::shared_ptr anAttr = - std::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - ObjectPtr aObj = anAttr->object(); - if (aObj.get() != NULL) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); - std::shared_ptr aSkFea = - std::dynamic_pointer_cast(aFeature); - if (!aSkFea->isExternal()) - anAIS = SketcherPrs_Factory::rigidConstraint(this, sketch()->coordinatePlane()); - } + + bool isValidRigid = false; + std::shared_ptr aData = data(); + AttributeRefAttrPtr anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj = anAttr->object(); + if (aObj.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + std::shared_ptr aSkFea = + std::dynamic_pointer_cast(aFeature); + if (!aSkFea->isExternal()) + isValidRigid = true; } + if (isValidRigid) + anAIS = SketcherPrs_Factory::rigidConstraint(this, sketch()->coordinatePlane(), thePrevious); + else + anAIS = AISObjectPtr(); + return anAIS; } \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_ConstraintTangent.cpp b/src/SketchPlugin/SketchPlugin_ConstraintTangent.cpp index 9d7256c18..767d3f13c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintTangent.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintTangent.cpp @@ -36,10 +36,8 @@ AISObjectPtr SketchPlugin_ConstraintTangent::getAISObject(AISObjectPtr thePrevio if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::tangentConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::tangentConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp b/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp index d5865e6ab..0520ca69e 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp @@ -35,10 +35,8 @@ AISObjectPtr SketchPlugin_ConstraintVertical::getAISObject(AISObjectPtr thePrevi if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::verticalConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::verticalConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index b44a26517..fcfd02624 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -204,10 +204,8 @@ AISObjectPtr SketchPlugin_MultiRotation::getAISObject(AISObjectPtr thePrevious) if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::rotateConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::rotateConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index 0b43bf38a..5e0a93098 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -191,10 +191,8 @@ AISObjectPtr SketchPlugin_MultiTranslation::getAISObject(AISObjectPtr thePreviou if (!sketch()) return thePrevious; - AISObjectPtr anAIS = thePrevious; - if (!anAIS) { - anAIS = SketcherPrs_Factory::translateConstraint(this, sketch()->coordinatePlane()); - } + AISObjectPtr anAIS = SketcherPrs_Factory::translateConstraint(this, sketch()->coordinatePlane(), + thePrevious); return anAIS; } diff --git a/src/SketcherPrs/SketcherPrs_Angle.cpp b/src/SketcherPrs/SketcherPrs_Angle.cpp index 04c7bd25e..30a95f51f 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.cpp +++ b/src/SketcherPrs/SketcherPrs_Angle.cpp @@ -43,33 +43,59 @@ SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight()); } +bool SketcherPrs_Angle::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + DataPtr aData = theConstraint->data(); + + // Flyout point + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + if (!aFlyoutAttr->isInitialized()) + return aReadyToDisplay; // can not create a good presentation + + AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + if (!anAttr1->isInitialized()) + return aReadyToDisplay; + + AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); + if (!anAttr2->isInitialized()) + return aReadyToDisplay; + + // Get angle edges + ObjectPtr aObj1 = anAttr1->object(); + ObjectPtr aObj2 = anAttr2->object(); + + std::shared_ptr aShape1 = SketcherPrs_Tools::getShape(aObj1); + std::shared_ptr aShape2 = SketcherPrs_Tools::getShape(aObj2); + + aReadyToDisplay = aShape1.get() && aShape2.get(); + return aReadyToDisplay; +} + void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { DataPtr aData = myConstraint->data(); + if (!IsReadyToDisplay(myConstraint, myPlane)) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); + return; // can not create a good presentation + } + // Flyout point std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - if (!aFlyoutAttr->isInitialized()) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); - return; // can not create a good presentation - } std::shared_ptr aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); - if (!anAttr1->isInitialized()) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); - return; - } - AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); - if (!anAttr2->isInitialized()) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); - return; - } + // Get angle edges ObjectPtr aObj1 = anAttr1->object(); ObjectPtr aObj2 = anAttr2->object(); @@ -77,11 +103,6 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP std::shared_ptr aShape1 = SketcherPrs_Tools::getShape(aObj1); std::shared_ptr aShape2 = SketcherPrs_Tools::getShape(aObj2); - if (!aShape1 && !aShape2) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle"); - return; - } - TopoDS_Shape aTEdge1 = aShape1->impl(); TopoDS_Shape aTEdge2 = aShape2->impl(); diff --git a/src/SketcherPrs/SketcherPrs_Angle.h b/src/SketcherPrs/SketcherPrs_Angle.h index d540dbbf5..0d87c02e3 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.h +++ b/src/SketcherPrs/SketcherPrs_Angle.h @@ -30,6 +30,13 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Angle) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: /// Redefinition of virtual function Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 764a45586..5c011bf5c 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -39,21 +39,36 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, } +bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + // Get point of the presentation + std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(theConstraint, + SketchPlugin_Constraint::ENTITY_A()); + if (aPnt.get() == NULL) + aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B()); + + aReadyToDisplay = aPnt.get() != NULL; + return aReadyToDisplay; +} void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { + if (!IsReadyToDisplay(myConstraint, myPlane)) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident"); + return; + } + // Get point of the presentation std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (aPnt.get() == NULL) aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (aPnt.get() == NULL) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident"); - return; - } std::shared_ptr aPoint = myPlane->to3D(aPnt->x(), aPnt->y()); myPoint = aPoint->impl(); diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h index 52ea362c5..88d08fe52 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.h +++ b/src/SketcherPrs/SketcherPrs_Coincident.h @@ -37,7 +37,14 @@ public: /// Defines color for the presentation /// \param aColor a color name Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor); - + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); + DEFINE_STANDARD_RTTI(SketcherPrs_Coincident) protected: /// Redefinition of virtual function diff --git a/src/SketcherPrs/SketcherPrs_Equal.cpp b/src/SketcherPrs/SketcherPrs_Equal.cpp index 9cfd69b59..ff5e21f10 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.cpp +++ b/src/SketcherPrs/SketcherPrs_Equal.cpp @@ -10,6 +10,8 @@ #include +#include "Events_Error.h" + #include #include @@ -28,14 +30,28 @@ SketcherPrs_Equal::SketcherPrs_Equal(ModelAPI_Feature* theConstraint, myPntArray->AddVertex(0., 0., 0.); } +bool SketcherPrs_Equal::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B()); + + aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL && + SketcherPrs_Tools::getShape(aObj2).get() != NULL; + + return aReadyToDisplay; +} + bool SketcherPrs_Equal::updatePoints(double theStep) const { + if (!IsReadyToDisplay(myConstraint, myPlane)) { + return false; + } + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) - return false; - if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) - return false; // Set points of the presentation SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); diff --git a/src/SketcherPrs/SketcherPrs_Equal.h b/src/SketcherPrs/SketcherPrs_Equal.h index d958d4124..bba05f150 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.h +++ b/src/SketcherPrs/SketcherPrs_Equal.h @@ -26,6 +26,13 @@ public: Standard_EXPORT SketcherPrs_Equal(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Equal) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: virtual const char* iconName() const { return "equal.png"; } diff --git a/src/SketcherPrs/SketcherPrs_Factory.cpp b/src/SketcherPrs/SketcherPrs_Factory.cpp index 24914e915..9ab167332 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.cpp +++ b/src/SketcherPrs/SketcherPrs_Factory.cpp @@ -22,12 +22,20 @@ // Macros for constraint presentation definition #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \ AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \ - const std::shared_ptr& thePlane) \ + const std::shared_ptr& thePlane, \ + AISObjectPtr thePrevious) \ { \ - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); \ - Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \ - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \ - return aAISObj; \ + std::shared_ptr anAISObj; \ + if (CLASS::IsReadyToDisplay(theConstraint, thePlane)) { \ + if (thePrevious.get()) \ + anAISObj = thePrevious; \ + else { \ + anAISObj = AISObjectPtr(new GeomAPI_AISObject()); \ + Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \ + anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \ + } \ + } \ + return anAISObj; \ } CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident); @@ -43,37 +51,69 @@ CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle); // Non-standard constraints definition AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) -{ - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, true); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); - return aAISObj; + const std::shared_ptr& thePlane, + AISObjectPtr thePrevious) +{ + std::shared_ptr anAISObj; + if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, thePlane)) { + if (thePrevious.get()) + anAISObj = thePrevious; + else { + anAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, true); + anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + } + } + return anAISObj; } AISObjectPtr SketcherPrs_Factory::verticalConstraint(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) + const std::shared_ptr& thePlane, + AISObjectPtr thePrevious) { - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, false); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); - return aAISObj; + std::shared_ptr anAISObj; + if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, thePlane)) { + if (thePrevious.get()) + anAISObj = thePrevious; + else { + anAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, false); + anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + } + } + return anAISObj; } AISObjectPtr SketcherPrs_Factory::translateConstraint(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) + const std::shared_ptr& thePlane, + AISObjectPtr thePrevious) { - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, true); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); - return aAISObj; + std::shared_ptr anAISObj; + if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint, thePlane)) { + if (thePrevious.get()) + anAISObj = thePrevious; + else { + anAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, true); + anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + } + } + return anAISObj; } AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstraint, - const std::shared_ptr& thePlane) + const std::shared_ptr& thePlane, + AISObjectPtr thePrevious) { - std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); - Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, false); - aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); - return aAISObj; + std::shared_ptr anAISObj; + if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint, thePlane)) { + if (thePrevious.get()) + anAISObj = thePrevious; + else { + anAISObj = AISObjectPtr(new GeomAPI_AISObject()); + Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, false); + anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); + } + } + return anAISObj; } diff --git a/src/SketcherPrs/SketcherPrs_Factory.h b/src/SketcherPrs/SketcherPrs_Factory.h index c0101fa0a..485c5a6fe 100644 --- a/src/SketcherPrs/SketcherPrs_Factory.h +++ b/src/SketcherPrs/SketcherPrs_Factory.h @@ -16,8 +16,8 @@ #define GET_CONSTRAINT_PRS(NAME) \ static AISObjectPtr NAME(ModelAPI_Feature* theConstraint, \ - const std::shared_ptr& thePlane); - + const std::shared_ptr& thePlane, \ + AISObjectPtr thePrevious); /** * Class which creates constraints presentations diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.cpp b/src/SketcherPrs/SketcherPrs_HVDirection.cpp index e7bdfdda7..c317a71b6 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.cpp +++ b/src/SketcherPrs/SketcherPrs_HVDirection.cpp @@ -13,6 +13,7 @@ #include #include +#include IMPLEMENT_STANDARD_HANDLE(SketcherPrs_HVDirection, SketcherPrs_SymbolPrs); @@ -29,13 +30,24 @@ SketcherPrs_HVDirection::SketcherPrs_HVDirection(ModelAPI_Feature* theConstraint myPntArray->AddVertex(0., 0., 0.); } +bool SketcherPrs_HVDirection::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + ObjectPtr aObj = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); + + aReadyToDisplay = SketcherPrs_Tools::getShape(aObj).get() != NULL; + return aReadyToDisplay; +} + bool SketcherPrs_HVDirection::updatePoints(double theStep) const { - ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - if (SketcherPrs_Tools::getShape(aObj).get() == NULL) + if (!SketcherPrs_HVDirection::IsReadyToDisplay(myConstraint, myPlane)) { return false; + } // Set point of the symbol + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(1, aP1); diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.h b/src/SketcherPrs/SketcherPrs_HVDirection.h index 9f6204d28..0f6bf64d3 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.h +++ b/src/SketcherPrs/SketcherPrs_HVDirection.h @@ -30,6 +30,14 @@ public: bool isHorisontal); DEFINE_STANDARD_RTTI(SketcherPrs_HVDirection) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); + protected: virtual const char* iconName() const { return myIsHorisontal? "horisontal.png" : "vertical.png"; } diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index 49415d7bb..b6df9e517 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -53,16 +53,29 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo SetDimensionAspect(myAspect); } +bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) +{ + bool aReadyToDisplay = false; + + gp_Pnt aPnt1, aPnt2; + aReadyToDisplay = getPoints(theConstraint, thePlane, aPnt1, aPnt2); + + return aReadyToDisplay; +} + void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { - gp_Pnt aPnt1, aPnt2; - if (!getPoints(aPnt1, aPnt2)) { + if (!SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, myPlane)) { Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension"); return; } + gp_Pnt aPnt1, aPnt2; + getPoints(myConstraint, myPlane, aPnt1, aPnt2); + // compute flyout distance SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint)); SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl()); @@ -94,10 +107,12 @@ void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManage AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode); } -bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) +bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane, + gp_Pnt& thePnt1, gp_Pnt& thePnt2) { - DataPtr aData = myConstraint->data(); - if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) { + DataPtr aData = theConstraint->data(); + if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) { // The constraint is length std::shared_ptr anAttr = std::dynamic_pointer_cast @@ -117,16 +132,16 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) std::shared_ptr aEndPoint = std::dynamic_pointer_cast (aLineData->attribute(SketchPlugin_Line::END_ID())); - thePnt1 = myPlane->to3D(aStartPoint->x(), aStartPoint->y())->impl(); - thePnt2 = myPlane->to3D(aEndPoint->x(), aEndPoint->y())->impl(); + thePnt1 = thePlane->to3D(aStartPoint->x(), aStartPoint->y())->impl(); + thePnt2 = thePlane->to3D(aEndPoint->x(), aEndPoint->y())->impl(); return true; - } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { + } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) { // The constraint is distance std::shared_ptr aPoint_A = SketcherPrs_Tools::getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_A(), myPlane); + aData, SketchPlugin_Constraint::ENTITY_A(), thePlane); std::shared_ptr aPoint_B = SketcherPrs_Tools::getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_B(), myPlane); + aData, SketchPlugin_Constraint::ENTITY_B(), thePlane); std::shared_ptr aPnt_A; std::shared_ptr aPnt_B; @@ -154,9 +169,9 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) if (!aPnt_A || !aPnt_B) // Objects not found return false; - // Get points from these objects - std::shared_ptr aPoint1 = myPlane->to3D(aPnt_A->x(), aPnt_A->y()); - std::shared_ptr aPoint2 = myPlane->to3D(aPnt_B->x(), aPnt_B->y()); + // Get points from these object + std::shared_ptr aPoint1 = thePlane->to3D(aPnt_A->x(), aPnt_A->y()); + std::shared_ptr aPoint2 = thePlane->to3D(aPnt_B->x(), aPnt_B->y()); thePnt1 = aPoint1->impl(); thePnt2 = aPoint2->impl(); return true; diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.h b/src/SketcherPrs/SketcherPrs_LengthDimension.h index 76e71c85d..cfd5d4881 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.h +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.h @@ -31,6 +31,13 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: /// Redefinition of virtual function Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, @@ -41,7 +48,9 @@ protected: const Standard_Integer aMode); private: - bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2); + static bool getPoints(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane, + gp_Pnt& thePnt1, gp_Pnt& thePnt2); /// Constraint feature ModelAPI_Feature* myConstraint; diff --git a/src/SketcherPrs/SketcherPrs_Mirror.cpp b/src/SketcherPrs/SketcherPrs_Mirror.cpp index 9719dc8cd..499cfc7a2 100644 --- a/src/SketcherPrs/SketcherPrs_Mirror.cpp +++ b/src/SketcherPrs/SketcherPrs_Mirror.cpp @@ -27,30 +27,53 @@ SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, { } - -bool SketcherPrs_Mirror::updatePoints(double theStep) const +bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) { + bool aReadyToDisplay = false; + // Get axis of mirror - ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL) - return false; + return aReadyToDisplay; - std::shared_ptr aData = myConstraint->data(); + std::shared_ptr aData = theConstraint->data(); // Get source objects std::shared_ptr anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B()); if (anAttrB.get() == NULL) - return false; + return aReadyToDisplay; // Get mirrored objects std::shared_ptr anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C()); if (anAttrC.get() == NULL) - return false; + return aReadyToDisplay; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); int aNb = anAttrB->size(); // If size of source objects and mirrored ones is not equal then the constraint is not computed if (aNb != anAttrC->size()) + return aReadyToDisplay; + + aReadyToDisplay = true; + return aReadyToDisplay; +} + +bool SketcherPrs_Mirror::updatePoints(double theStep) const +{ + if (!IsReadyToDisplay(myConstraint, myPlane)) return false; + // Get axis of mirror + ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + + std::shared_ptr aData = myConstraint->data(); + // Get source objects + std::shared_ptr anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B()); + // Get mirrored objects + std::shared_ptr anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C()); + + SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); + int aNb = anAttrB->size(); + myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb); int i; ObjectPtr aObj; diff --git a/src/SketcherPrs/SketcherPrs_Mirror.h b/src/SketcherPrs/SketcherPrs_Mirror.h index 69e9494d9..35d5c146c 100644 --- a/src/SketcherPrs/SketcherPrs_Mirror.h +++ b/src/SketcherPrs/SketcherPrs_Mirror.h @@ -26,6 +26,13 @@ public: Standard_EXPORT SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Mirror) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: virtual const char* iconName() const { return "mirror.png"; } diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index 1b6712d9e..3a4d3be35 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -30,15 +30,26 @@ SketcherPrs_Parallel::SketcherPrs_Parallel(ModelAPI_Feature* theConstraint, myPntArray->AddVertex(0., 0., 0.); } +bool SketcherPrs_Parallel::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B()); + + aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL && + SketcherPrs_Tools::getShape(aObj2).get() != NULL; + return aReadyToDisplay; +} bool SketcherPrs_Parallel::updatePoints(double theStep) const { + if (!IsReadyToDisplay(myConstraint, myPlane)) + return false; + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) - return false; - if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) - return false; // Compute position of symbols SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); diff --git a/src/SketcherPrs/SketcherPrs_Parallel.h b/src/SketcherPrs/SketcherPrs_Parallel.h index 3194a63cc..e2d415fb7 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.h +++ b/src/SketcherPrs/SketcherPrs_Parallel.h @@ -26,6 +26,14 @@ public: Standard_EXPORT SketcherPrs_Parallel(ModelAPI_Feature* theConstraint, const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Parallel) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); + protected: virtual const char* iconName() const { return "parallel.png"; } diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index dfc6964e6..cb5302eef 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -30,15 +30,26 @@ SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(ModelAPI_Feature* theConstr myPntArray->AddVertex(0., 0., 0.); } +bool SketcherPrs_Perpendicular::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B()); + + aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL && + SketcherPrs_Tools::getShape(aObj2).get() != NULL; + return aReadyToDisplay; +} bool SketcherPrs_Perpendicular::updatePoints(double theStep) const { + if (!IsReadyToDisplay(myConstraint, myPlane)) + return false; + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) - return false; - if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) - return false; // Compute position of symbols SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.h b/src/SketcherPrs/SketcherPrs_Perpendicular.h index 6cabbf03a..42bcf7953 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.h +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.h @@ -29,6 +29,13 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: virtual const char* iconName() const { return "perpendicular.png"; } diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index d26d3e539..62a50a46f 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -44,26 +44,27 @@ SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint, SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight()); } -void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, - const Handle(Prs3d_Presentation)& thePresentation, - const Standard_Integer theMode) +bool SketcherPrs_Radius::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) { - DataPtr aData = myConstraint->data(); + bool aReadyToDisplay = false; + + DataPtr aData = theConstraint->data(); // Flyout point std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); if (!aFlyoutAttr->isInitialized()) { - Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius"); - return; // can not create a good presentation + return aReadyToDisplay; // can not create a good presentation } // Get circle std::shared_ptr anAttr = std::dynamic_pointer_cast (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - if (!anAttr) return; + if (!anAttr) + return aReadyToDisplay; std::shared_ptr aCyrcFeature = ModelAPI_Feature::feature(anAttr->object()); double aRadius = 1; @@ -71,7 +72,62 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the // it is possible that circle result becomes zero, in this case the presentation should disappear // for example, it happens when circle radius is set to zero if (!aCyrcFeature) + return aReadyToDisplay; + if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle + aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + AttributeDoublePtr aCircRadius = + std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID())); + aRadius = aCircRadius->value(); + } else { // arc + aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); + std::shared_ptr aStartAttr = + std::dynamic_pointer_cast + (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID())); + aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + } + std::shared_ptr aCenter = thePlane->to3D(aCenterAttr->x(), aCenterAttr->y()); + std::shared_ptr aNormal = thePlane->normal(); + + GeomAPI_Circ aCircle(aCenter, aNormal, aRadius); + + std::shared_ptr anAnchor = SketcherPrs_Tools::getAnchorPoint(theConstraint, thePlane); + + gp_Circ aCirc = aCircle.impl(); + gp_Pnt anAncorPnt = anAnchor->impl(); + // anchor point should not coincide to the location point of the circle + // OCCT does not process this case. + + aReadyToDisplay = anAncorPnt.Distance(aCirc.Location()) > 1e-7; + return aReadyToDisplay; +} + +void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + if (!IsReadyToDisplay(myConstraint, myPlane)) { + Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius"); return; + } + + DataPtr aData = myConstraint->data(); + + // Flyout point + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + + // Get circle + std::shared_ptr anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + + std::shared_ptr aCyrcFeature = ModelAPI_Feature::feature(anAttr->object()); + double aRadius = 1; + std::shared_ptr aCenterAttr; if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle aCenterAttr = std::dynamic_pointer_cast( aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); @@ -96,10 +152,7 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the gp_Circ aCirc = aCircle.impl(); gp_Pnt anAncorPnt = anAnchor->impl(); - // anchor point should not coincide to the location point of the circle - // OCCT does not process this case. - if (anAncorPnt.Distance(aCirc.Location()) < 1e-7) - return; + SetMeasuredGeometry(aCirc, anAncorPnt); SetCustomValue(aRadius); diff --git a/src/SketcherPrs/SketcherPrs_Radius.h b/src/SketcherPrs/SketcherPrs_Radius.h index 88a3c613c..ea0dc90d4 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.h +++ b/src/SketcherPrs/SketcherPrs_Radius.h @@ -30,6 +30,13 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Radius) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: /// Redefinition of virtual function Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, diff --git a/src/SketcherPrs/SketcherPrs_Rigid.cpp b/src/SketcherPrs/SketcherPrs_Rigid.cpp index 2fc417fed..71122d431 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.cpp +++ b/src/SketcherPrs/SketcherPrs_Rigid.cpp @@ -46,26 +46,47 @@ SketcherPrs_Rigid::SketcherPrs_Rigid(ModelAPI_Feature* theConstraint, myPntArray->AddVertex(0., 0., 0.); } +bool SketcherPrs_Rigid::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) +{ + bool aReadyToDisplay = false; + + std::shared_ptr aData = theConstraint->data(); + std::shared_ptr anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + AttributePtr aRefAttr = anAttr->attr(); + if (anAttr->isObject()) { + // The constraint attached to an object + ObjectPtr aObj = anAttr->object(); + aReadyToDisplay = SketcherPrs_Tools::getShape(aObj).get() != NULL; + + } else { + // The constraint attached to a point + std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(theConstraint, + SketchPlugin_Constraint::ENTITY_A()); + aReadyToDisplay = aPnt.get() != NULL; + } + return aReadyToDisplay; +} bool SketcherPrs_Rigid::updatePoints(double theStep) const { + if (!IsReadyToDisplay(myConstraint, myPlane)) + return false; + std::shared_ptr aData = myConstraint->data(); std::shared_ptr anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); AttributePtr aRefAttr = anAttr->attr(); if (anAttr->isObject()) { // The constraint attached to an object ObjectPtr aObj = anAttr->object(); - if (SketcherPrs_Tools::getShape(aObj).get() == NULL) - return false; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep); myPntArray->SetVertice(1, aP1); } else { // The constraint attached to a point - std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A()); - if (aPnt.get() == NULL) - return false; + std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(myConstraint, + SketchPlugin_Constraint::ENTITY_A()); std::shared_ptr aPoint = myPlane->to3D(aPnt->x(), aPnt->y() + theStep); myPntArray->SetVertice(1, aPoint->impl()); } diff --git a/src/SketcherPrs/SketcherPrs_Rigid.h b/src/SketcherPrs/SketcherPrs_Rigid.h index cabccbf07..cf9d50427 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.h +++ b/src/SketcherPrs/SketcherPrs_Rigid.h @@ -30,6 +30,13 @@ public: DEFINE_STANDARD_RTTI(SketcherPrs_Rigid) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: virtual const char* iconName() const { return "anchor.png"; } diff --git a/src/SketcherPrs/SketcherPrs_Tangent.cpp b/src/SketcherPrs/SketcherPrs_Tangent.cpp index c9adc9b55..57fd51779 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.cpp +++ b/src/SketcherPrs/SketcherPrs_Tangent.cpp @@ -33,14 +33,24 @@ SketcherPrs_Tangent::SketcherPrs_Tangent(ModelAPI_Feature* theConstraint, myPntArray->AddVertex(0., 0., 0.); } +bool SketcherPrs_Tangent::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) +{ + bool aReadyToDisplay = false; + + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B()); + + aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL && + SketcherPrs_Tools::getShape(aObj2).get() != NULL; + + return aReadyToDisplay; +} + bool SketcherPrs_Tangent::updatePoints(double theStep) const { ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); - if (SketcherPrs_Tools::getShape(aObj1).get() == NULL) - return false; - if (SketcherPrs_Tools::getShape(aObj2).get() == NULL) - return false; // Compute points coordinates SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); diff --git a/src/SketcherPrs/SketcherPrs_Tangent.h b/src/SketcherPrs/SketcherPrs_Tangent.h index 78aaff550..baed8cf7d 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.h +++ b/src/SketcherPrs/SketcherPrs_Tangent.h @@ -28,6 +28,13 @@ public: const std::shared_ptr& thePlane); DEFINE_STANDARD_RTTI(SketcherPrs_Tangent) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: virtual const char* iconName() const { return "tangent.png"; } diff --git a/src/SketcherPrs/SketcherPrs_Transformation.cpp b/src/SketcherPrs/SketcherPrs_Transformation.cpp index cd6f54a76..347f8c357 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.cpp +++ b/src/SketcherPrs/SketcherPrs_Transformation.cpp @@ -35,14 +35,31 @@ SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theCons { } -bool SketcherPrs_Transformation::updatePoints(double theStep) const +bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr&/* thePlane*/) { - std::shared_ptr aData = myConstraint->data(); + bool aReadyToDisplay = false; + + std::shared_ptr aData = theConstraint->data(); // Get transformated objects list std::shared_ptr anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B()); if (anAttrB.get() == NULL) + return aReadyToDisplay; + + int aNbB = anAttrB->size(); + aReadyToDisplay = aNbB > 0; + return aReadyToDisplay; +} + +bool SketcherPrs_Transformation::updatePoints(double theStep) const +{ + if (!IsReadyToDisplay(myConstraint, myPlane)) return false; + std::shared_ptr aData = myConstraint->data(); + // Get transformated objects list + std::shared_ptr anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B()); + int aNbB = anAttrB->size(); if (aNbB == 0) { @@ -50,7 +67,6 @@ bool SketcherPrs_Transformation::updatePoints(double theStep) const //if (!myPntArray.IsNull()) // mySPoints.Clear(); #endif - return false; } SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); diff --git a/src/SketcherPrs/SketcherPrs_Transformation.h b/src/SketcherPrs/SketcherPrs_Transformation.h index ea28b24a3..a41c9a0e0 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.h +++ b/src/SketcherPrs/SketcherPrs_Transformation.h @@ -30,6 +30,13 @@ public: bool isTranslation); DEFINE_STANDARD_RTTI(SketcherPrs_Transformation) + + /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation + /// \param theConstraint a constraint feature + /// \param thePlane a coordinate plane of current sketch + /// \return boolean result value + static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane); protected: virtual const char* iconName() const { return myIsTranslation? "translate.png" : "rotate.png"; } -- 2.39.2