]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
empty AIS presentation should not be visualized in the viewer. It is caused by OCCT...
authornds <nds@opencascade.com>
Thu, 18 Feb 2016 13:22:09 +0000 (16:22 +0300)
committernds <nds@opencascade.com>
Thu, 18 Feb 2016 13:22:34 +0000 (16:22 +0300)
43 files changed:
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp
src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp
src/SketchPlugin/SketchPlugin_ConstraintCollinear.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp
src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintMiddle.cpp
src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp
src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp
src/SketchPlugin/SketchPlugin_ConstraintTangent.cpp
src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp
src/SketchPlugin/SketchPlugin_MultiRotation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketcherPrs/SketcherPrs_Angle.cpp
src/SketcherPrs/SketcherPrs_Angle.h
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/SketcherPrs/SketcherPrs_Coincident.h
src/SketcherPrs/SketcherPrs_Equal.cpp
src/SketcherPrs/SketcherPrs_Equal.h
src/SketcherPrs/SketcherPrs_Factory.cpp
src/SketcherPrs/SketcherPrs_Factory.h
src/SketcherPrs/SketcherPrs_HVDirection.cpp
src/SketcherPrs/SketcherPrs_HVDirection.h
src/SketcherPrs/SketcherPrs_LengthDimension.cpp
src/SketcherPrs/SketcherPrs_LengthDimension.h
src/SketcherPrs/SketcherPrs_Mirror.cpp
src/SketcherPrs/SketcherPrs_Mirror.h
src/SketcherPrs/SketcherPrs_Parallel.cpp
src/SketcherPrs/SketcherPrs_Parallel.h
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_Perpendicular.h
src/SketcherPrs/SketcherPrs_Radius.cpp
src/SketcherPrs/SketcherPrs_Radius.h
src/SketcherPrs/SketcherPrs_Rigid.cpp
src/SketcherPrs/SketcherPrs_Rigid.h
src/SketcherPrs/SketcherPrs_Tangent.cpp
src/SketcherPrs/SketcherPrs_Tangent.h
src/SketcherPrs/SketcherPrs_Transformation.cpp
src/SketcherPrs/SketcherPrs_Transformation.h

index 646e4b800fcc0cc81a72b4593dba4adb11cf7d38..ef711f6a5af03db16b692cfa6eba9e1d02208da9 100644 (file)
@@ -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;
 }
 
index b1fb8be9733879d14069da7b70a04eef4054b8f7..ed40959083e55defeb23a657f35f16622159f940 100644 (file)
@@ -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;
 }
 
index 75da202f148f62dac8a87d9cd24a30e43b8733b4..d7c7e07c32df00659cea97abb2e61675743d0093 100644 (file)
@@ -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;
 }
 
index 583477a02282651e26ee1afec8051a0729a2a988..ea131563fb568aaca69d614218be7e475c4d7acb 100644 (file)
@@ -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;
 }
 
index 1b80c0c6b050e16088bea1b496c263716c60a5f0..e63764802a3f0d65cb2f3f0d5e217eb9dbe27c79 100644 (file)
@@ -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;
 }
 
index 0f7aa24926376731fc126ddd956c34badf04853c..558b44a3ddaa4aa6eea1af177f350db1f23579c2 100644 (file)
@@ -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;
 }
 
-
index e97b821414417350eed77d5b4838aec3b0108058..949908b293f628672969fdd7e52a85d5b3204d34 100644 (file)
@@ -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;
 }
 
index 76e8509cbc012e72a79c645c2f9d9601207b0770..7112d440101f6283295d6e73372595b221e69949 100644 (file)
@@ -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;
 }
 
index 4b3bbb997422f734031314f85a4ac833366c00c8..e17a704c5b5238d08f313cc0766a8eb9e39ec147 100755 (executable)
@@ -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;
 }
 
index 42ce74b78572f01ad5a9af1544e639eca8544320..7a6f71af5650be85384f0ec15cb6d5111553cd37 100644 (file)
@@ -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;
 }
 
index eb9ec92f5866d8ba552b5e798bfcfd88bfaf8ed6..c7e327fa13d481d1da4baf6cbb702f0b683601e4 100644 (file)
@@ -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;
 }
 
index e9ce8ae6a5990da4cc541cd63139193fa88b76be..f4bf1708fc2273349078a8a8a88c8d0c637068ee 100644 (file)
@@ -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;
 }
 
index 8867e16d55932720530b9e6e0ea9dde72eeb88b6..418c0dd53a523e12590e40f59cc392df7b5b4b1f 100644 (file)
@@ -35,19 +35,23 @@ AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious
     return thePrevious;
 
   AISObjectPtr anAIS = thePrevious;
-  if (anAIS.get() == NULL) {
-    std::shared_ptr<ModelAPI_Data> aData = data();
-    std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-    ObjectPtr aObj = anAttr->object();
-    if (aObj.get() != NULL) {
-      FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
-      std::shared_ptr<SketchPlugin_Feature> aSkFea = 
-        std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
-      if (!aSkFea->isExternal()) 
-        anAIS = SketcherPrs_Factory::rigidConstraint(this, sketch()->coordinatePlane());
-    }
+
+  bool isValidRigid = false;
+  std::shared_ptr<ModelAPI_Data> 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<SketchPlugin_Feature> aSkFea = 
+      std::dynamic_pointer_cast<SketchPlugin_Feature>(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
index 9d7256c18aef20b54139ab02501caa55b4159c6e..767d3f13cc5d494d8a75d0139a1f4f36e9978d21 100644 (file)
@@ -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;
 }
 
index d5865e6ab3c14aafc6e2bb7da8fd13b75c992cd2..0520ca69ebca18eaeeeeda8364017347d5ea147b 100644 (file)
@@ -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;
 }
 
index b44a26517e61bb46c4455b915b5f3b9baa1dc1e3..fcfd0262485515979dc1ff078482ac9c0e0f2fff 100755 (executable)
@@ -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;
 }
 
index 0b43bf38ada6e9ba291a9ec00dadf5553616d25f..5e0a93098924892d5c215b3c6db5ddcbfa16b9a6 100755 (executable)
@@ -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;
 }
 
index 04c7bd25e4da75d3c7147890e4142dcdb49b17dd..30a95f51f061585b07561d0624e28a398b48305c 100644 (file)
@@ -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<GeomAPI_Ax3>&/* thePlane*/)
+{
+  bool aReadyToDisplay = false;
+
+  DataPtr aData = theConstraint->data();
+
+  // Flyout point
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
+    std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+    (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<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
+  std::shared_ptr<GeomAPI_Shape> 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<GeomDataAPI_Point2D> aFlyoutAttr = 
     std::dynamic_pointer_cast<GeomDataAPI_Point2D>
     (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<GeomAPI_Pnt> 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<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
   std::shared_ptr<GeomAPI_Shape> 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>();
   TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
 
index d540dbbf5f012a15beb908057395691b309d31ab..0d87c02e3bc71cf56c8257d7a24d7bbd82be1431 100644 (file)
@@ -30,6 +30,13 @@ public:
                         const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
 protected:
   /// Redefinition of virtual function
   Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
index 764a45586870526e7ddb7a374def2fc425496c17..5c011bf5c9bd3b1b9d20e3baf5015e9188198796 100644 (file)
@@ -39,21 +39,36 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
   
 }  
 
+bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+                                              const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+  bool aReadyToDisplay = false;
+
+  // Get point of the presentation
+  std::shared_ptr<GeomAPI_Pnt2d> 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<GeomAPI_Pnt2d> 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<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
   myPoint = aPoint->impl<gp_Pnt>();
 
index 52ea362c58bb1b37c6b7944e3456c26054e38bc0..88d08fe525e25755cb511e00d5c5f1b4e2985926 100644 (file)
@@ -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<GeomAPI_Ax3>& thePlane);
+
   DEFINE_STANDARD_RTTI(SketcherPrs_Coincident)
 protected:
   /// Redefinition of virtual function
index 9cfd69b595de843b8e1ff87db92f72ad0c6c8590..ff5e21f101139ddfeb2aeb7a73b4a717f15d04cd 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <SketchPlugin_Constraint.h>
 
+#include "Events_Error.h"
+
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Prs3d_Root.hxx>
 
@@ -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<GeomAPI_Ax3>&/* 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();
index d958d412488c0c90cbe021e2e81eed08bcd5a35f..bba05f150c44b9da3177fd912fe5d8a8dc5db7a8 100644 (file)
@@ -26,6 +26,13 @@ public:
   Standard_EXPORT SketcherPrs_Equal(ModelAPI_Feature* theConstraint, 
                                        const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
 protected:
 
   virtual const char* iconName() const { return "equal.png"; }
index 24914e915e31e80f8d157a7cffdec4f913af5f72..9ab167332603e1e0218ade9ae98f18700e592638 100644 (file)
 // Macros for constraint presentation definition
 #define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
 AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
-                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane) \
+                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane, \
+                                       AISObjectPtr thePrevious) \
 { \
-  std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
-  Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \
-  aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
-  return aAISObj; \
+  std::shared_ptr<GeomAPI_AISObject> 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<GeomAPI_Ax3>& thePlane)
-{ 
-  std::shared_ptr<GeomAPI_AISObject> 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<GeomAPI_Ax3>& thePlane,
+                                       AISObjectPtr thePrevious)
+{
+  std::shared_ptr<GeomAPI_AISObject> 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<GeomAPI_Ax3>& thePlane)
+                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                       AISObjectPtr thePrevious)
 { 
-  std::shared_ptr<GeomAPI_AISObject> 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<GeomAPI_AISObject> 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<GeomAPI_Ax3>& thePlane)
+                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                       AISObjectPtr thePrevious)
 { 
-  std::shared_ptr<GeomAPI_AISObject> 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<GeomAPI_AISObject> 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<GeomAPI_Ax3>& thePlane)
+                                       const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+                                       AISObjectPtr thePrevious)
 { 
-  std::shared_ptr<GeomAPI_AISObject> 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<GeomAPI_AISObject> 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;
 }
index c0101fa0a47a3b39231c246ae94c9be64dcc59bb..485c5a6fe0457622b2b2e7a30531fa1fbef1122d 100644 (file)
@@ -16,8 +16,8 @@
 
 #define GET_CONSTRAINT_PRS(NAME) \
   static AISObjectPtr NAME(ModelAPI_Feature* theConstraint, \
-                           const std::shared_ptr<GeomAPI_Ax3>& thePlane);
-
+                           const std::shared_ptr<GeomAPI_Ax3>& thePlane, \
+                           AISObjectPtr thePrevious);
 
 /**
 * Class which creates constraints presentations
index e7bdfdda7c5fba61a891484b0c9b10144e983501..c317a71b606bd810c7da23ed691b2b2269d2d7d9 100644 (file)
@@ -13,6 +13,7 @@
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Prs3d_Root.hxx>
 
+#include <Events_Error.h>
 
 
 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<GeomAPI_Ax3>&/* 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);
index 9f6204d2841dda5230b538c365e8f05023264d27..0f6bf64d3330bd76c225be7f5892319218b53799 100644 (file)
@@ -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<GeomAPI_Ax3>& thePlane);
+
 protected:
   virtual const char* iconName() const { return myIsHorisontal? "horisontal.png" : "vertical.png"; }
 
index 49415d7bbfbb5ffa2c03f690aa75a29d23c2b818..b6df9e517274bfc4ccec6a73535835ae3da0baad 100644 (file)
@@ -53,16 +53,29 @@ SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(ModelAPI_Feature* theCo
   SetDimensionAspect(myAspect);
 }
 
+bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+                                         const std::shared_ptr<GeomAPI_Ax3>& 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<gp_Ax3>());
@@ -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<GeomAPI_Ax3>& 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<ModelAPI_AttributeRefAttr> anAttr = 
       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
@@ -117,16 +132,16 @@ bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
     std::shared_ptr<GeomDataAPI_Point2D> aEndPoint = 
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>
       (aLineData->attribute(SketchPlugin_Line::END_ID()));
-    thePnt1 = myPlane->to3D(aStartPoint->x(), aStartPoint->y())->impl<gp_Pnt>();
-    thePnt2 = myPlane->to3D(aEndPoint->x(), aEndPoint->y())->impl<gp_Pnt>();
+    thePnt1 = thePlane->to3D(aStartPoint->x(), aStartPoint->y())->impl<gp_Pnt>();
+    thePnt2 = thePlane->to3D(aEndPoint->x(), aEndPoint->y())->impl<gp_Pnt>();
     return true;
 
-  } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
+  } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
     // The constraint is distance
     std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
-        aData, SketchPlugin_Constraint::ENTITY_A(), myPlane);
+        aData, SketchPlugin_Constraint::ENTITY_A(), thePlane);
     std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
-        aData, SketchPlugin_Constraint::ENTITY_B(), myPlane);
+        aData, SketchPlugin_Constraint::ENTITY_B(), thePlane);
 
     std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
     std::shared_ptr<GeomAPI_Pnt2d> 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<GeomAPI_Pnt> aPoint1 = myPlane->to3D(aPnt_A->x(), aPnt_A->y());
-    std::shared_ptr<GeomAPI_Pnt> aPoint2 = myPlane->to3D(aPnt_B->x(), aPnt_B->y());
+    // Get points from these object
+    std::shared_ptr<GeomAPI_Pnt> aPoint1 = thePlane->to3D(aPnt_A->x(), aPnt_A->y());
+    std::shared_ptr<GeomAPI_Pnt> aPoint2 = thePlane->to3D(aPnt_B->x(), aPnt_B->y());
     thePnt1 = aPoint1->impl<gp_Pnt>();
     thePnt2 = aPoint2->impl<gp_Pnt>();
     return true;
index 76e71c85dab70e0568ae055760b8ef79c9a3257e..cfd5d4881f8947188ded63360de8a132c5fe2025 100644 (file)
@@ -31,6 +31,13 @@ public:
                         const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane,
+                 gp_Pnt& thePnt1, gp_Pnt& thePnt2);
 
   /// Constraint feature
   ModelAPI_Feature* myConstraint;
index 9719dc8cd066175fdc641e7fa98217cfe5f865f7..499cfc7a23fc6b01e937ffa10b09ff6fa14d1d53 100644 (file)
@@ -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<GeomAPI_Ax3>&/* 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<ModelAPI_Data> aData = myConstraint->data();
+  std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
   // Get source objects
   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
   if (anAttrB.get() == NULL)
-    return false;
+    return aReadyToDisplay;
   // Get mirrored objects
   std::shared_ptr<ModelAPI_AttributeRefList> 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<ModelAPI_Data> aData = myConstraint->data();
+  // Get source objects
+  std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
+  // Get mirrored objects
+  std::shared_ptr<ModelAPI_AttributeRefList> 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;
index 69e9494d95aa3017a78ca6f17e88b5a5ef1a4fa3..35d5c146cf1cd9496744630a440b1805dd865af6 100644 (file)
@@ -26,6 +26,13 @@ public:
   Standard_EXPORT SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, 
                                        const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
 protected:
   virtual const char* iconName() const { return "mirror.png"; }
 
index 1b6712d9ea90e2c98e2d5f95436c54377c830d5d..3a4d3be35020711da35aa3eaab395d64afa8075b 100644 (file)
@@ -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<GeomAPI_Ax3>&/* 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();
index 3194a63cce7c2bc376d37dd38a87944582c8d912..e2d415fb700732666fc8b77e6e24678492e7385e 100644 (file)
@@ -26,6 +26,14 @@ public:
   Standard_EXPORT SketcherPrs_Parallel(ModelAPI_Feature* theConstraint, 
                                        const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
+
 protected:
   virtual const char* iconName() const { return "parallel.png"; }
 
index dfc6964e681abfa6b78033f6b03e31846cc7ef24..cb5302eefa0311e098ee4ec3e694628fed478507 100644 (file)
@@ -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<GeomAPI_Ax3>&/* 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();
index 6cabbf03a4807a5ed0100904bdb30d0c424f8bb6..42bcf79538922e39b5a131fcdaafd58d99734438 100644 (file)
@@ -29,6 +29,13 @@ public:
                                        const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
 protected:
   virtual const char* iconName() const { return "perpendicular.png"; }
 
index d26d3e539463d0e0992e7b96c9291b7674961b42..62a50a46fd8366dde654873fe94a117953890dc9 100644 (file)
@@ -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<GeomAPI_Ax3>& thePlane)
 {
-  DataPtr aData = myConstraint->data();
+  bool aReadyToDisplay = false;
+
+  DataPtr aData = theConstraint->data();
 
   // Flyout point
   std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
     std::dynamic_pointer_cast<GeomDataAPI_Point2D>
     (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<ModelAPI_AttributeRefAttr> anAttr = 
     std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
     (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-  if (!anAttr) return;
+  if (!anAttr)
+    return aReadyToDisplay;
 
   std::shared_ptr<ModelAPI_Feature> 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<GeomDataAPI_Point2D>(
+        aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+    AttributeDoublePtr aCircRadius = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+      aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
+    aRadius = aCircRadius->value();
+  } else { // arc
+    aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+    std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+      (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
+    aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+  }
+  std::shared_ptr<GeomAPI_Pnt> aCenter = thePlane->to3D(aCenterAttr->x(), aCenterAttr->y());
+  std::shared_ptr<GeomAPI_Dir> aNormal = thePlane->normal();
+
+  GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
+    
+  std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(theConstraint, thePlane);
+
+  gp_Circ aCirc = aCircle.impl<gp_Circ>();
+  gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
+  // 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<GeomDataAPI_Point2D> aFlyoutAttr = 
+    std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+    (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+
+  // Get circle
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+    (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+
+  std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
+  double aRadius = 1;
+  std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
   if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
     aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
         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_Circ>();
   gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
-  // 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);
 
index 88a3c613c219d445c55f95b06e018bd38682e8b2..ea0dc90d44273bba7f35de53814a54e67d014f50 100644 (file)
@@ -30,6 +30,13 @@ public:
                         const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
 protected:
   /// Redefinition of virtual function
   Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
index 2fc417fedd38a16c02b4e7e2468c8bbc07df1914..71122d431a4e0df0030e417815e0cf9bd60c23c8 100644 (file)
@@ -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<GeomAPI_Ax3>& thePlane)
+{
+  bool aReadyToDisplay = false;
+
+  std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
+  std::shared_ptr<ModelAPI_AttributeRefAttr> 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<GeomAPI_Pnt2d> 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<ModelAPI_Data> aData = myConstraint->data();
   std::shared_ptr<ModelAPI_AttributeRefAttr> 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<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-    if (aPnt.get() == NULL)
-      return false;
+    std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
+                                                  SketchPlugin_Constraint::ENTITY_A());
     std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y() + theStep);
     myPntArray->SetVertice(1, aPoint->impl<gp_Pnt>());
   }
index cabccbf07e2928bae5292a74036ddb4d750409b2..cf9d5042709ad139f9e9a80d35bf7e53250ad059 100644 (file)
@@ -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<GeomAPI_Ax3>& thePlane);
 protected:
   virtual const char* iconName() const { return "anchor.png"; }
 
index c9adc9b55f38671a6fd811576aafc6f99144c009..57fd517797506cbab8e7f6f8f2f323d6112a3153 100644 (file)
@@ -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<GeomAPI_Ax3>&/* 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();
index 78aaff550be0a6b1aba32a65701e76325c86ade5..baed8cf7d988478b8582d447de568a58ba72867b 100644 (file)
@@ -28,6 +28,13 @@ public:
                                        const std::shared_ptr<GeomAPI_Ax3>& 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<GeomAPI_Ax3>& thePlane);
 protected:
 
   virtual const char* iconName() const { return "tangent.png"; }
index cd6f54a7697dbf104fc32164c0a7961dfaaa5d01..347f8c3578b9358717c1c6b8baaa365613acd689 100644 (file)
@@ -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<GeomAPI_Ax3>&/* thePlane*/)
 {
-  std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+  bool aReadyToDisplay = false;
+
+  std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
   // Get transformated objects list
   std::shared_ptr<ModelAPI_AttributeRefList> 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<ModelAPI_Data> aData = myConstraint->data();
+  // Get transformated objects list
+  std::shared_ptr<ModelAPI_AttributeRefList> 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();
index ea28b24a3f64a660505fd1cf5011d3531c90a2b9..a41c9a0e067b45b75e5a8b919033827b75c22a63 100644 (file)
@@ -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<GeomAPI_Ax3>& thePlane);
 protected:
   virtual const char* iconName() const { return myIsTranslation? "translate.png" : "rotate.png"; }