Salome HOME
Add Chamfer feature
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Measurement.cpp
index ee4d1ea1f4ec0ee2d4700df5e766f45e6d640603..8318f3d08779db0209e154872c4e5923f8be6592 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+// Copyright (C) 2018-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "FeaturesPlugin_Measurement.h"
@@ -318,6 +317,18 @@ void FeaturesPlugin_Measurement::computeAngleByPoints()
 
 AISObjectPtr FeaturesPlugin_Measurement::getAISObject(AISObjectPtr thePrevious)
 {
+  AttributeDoubleArrayPtr aValues =
+    std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+  if ((aValues->size() == 0) || (aValues->value(0) <= Precision::Confusion()))
+    return AISObjectPtr();
+
+  if (!myScreenPlane) {
+    // initialize a default plane for dimension
+    GeomPointPtr anOrigin(new GeomAPI_Pnt(0., 0., 0.));
+    GeomDirPtr aNormal(new GeomAPI_Dir(0., 0., 1.));
+    myScreenPlane = GeomPlanePtr(new GeomAPI_Pln(anOrigin, aNormal));
+  }
+
   AISObjectPtr anAIS;
   std::string aKind = string(MEASURE_KIND())->value();
   if (aKind == MEASURE_LENGTH())
@@ -337,8 +348,6 @@ AISObjectPtr FeaturesPlugin_Measurement::getAISObject(AISObjectPtr thePrevious)
 AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePrevious)
 {
   AISObjectPtr aAISObj;
-  if (!myScreenPlane.get())
-    return aAISObj;
 
   AttributeSelectionPtr aSelectedFeature = selection(EDGE_FOR_LENGTH_ID());
 
@@ -378,6 +387,7 @@ AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePreviou
         aDim = Handle(AIS_LengthDimension)::DownCast(aAIS);
         if (aDim.IsNull()) {
           aDim = new AIS_LengthDimension(aTEdge, aPlane);
+          aAISObj = AISObjectPtr(new GeomAPI_AISObject());
           aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim));
         }
         else {
@@ -398,8 +408,6 @@ AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePreviou
 AISObjectPtr FeaturesPlugin_Measurement::distanceDimension(AISObjectPtr thePrevious)
 {
   AISObjectPtr aAISObj;
-  if (!myScreenPlane.get())
-    return aAISObj;
 
   AttributeSelectionPtr aFirstFeature = selection(DISTANCE_FROM_OBJECT_ID());
   AttributeSelectionPtr aSecondFeature = selection(DISTANCE_TO_OBJECT_ID());
@@ -442,6 +450,7 @@ AISObjectPtr FeaturesPlugin_Measurement::distanceDimension(AISObjectPtr thePrevi
             aDim = Handle(AIS_LengthDimension)::DownCast(aAIS);
             if (aDim.IsNull()) {
               aDim = new AIS_LengthDimension(aPnt1, aPnt2, aPlane);
+              aAISObj = AISObjectPtr(new GeomAPI_AISObject());
               aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim));
             }
             else {
@@ -482,6 +491,7 @@ AISObjectPtr FeaturesPlugin_Measurement::radiusDimension(AISObjectPtr thePreviou
       Handle(AIS_RadiusDimension) aDim = Handle(AIS_RadiusDimension)::DownCast(aAIS);
       if (aDim.IsNull()) {
         aDim = new AIS_RadiusDimension(aShp);
+        aAISObj = AISObjectPtr(new GeomAPI_AISObject());
         aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim));
       } else
         aDim->SetMeasuredGeometry(aShp);
@@ -522,6 +532,7 @@ AISObjectPtr FeaturesPlugin_Measurement::angleDimension(AISObjectPtr thePrevious
   if (anEdge1.get() && anEdge2.get()) {
     TopoDS_Edge aTEdge1 = TopoDS::Edge(anEdge1->impl<TopoDS_Shape>());
     TopoDS_Edge aTEdge2 = TopoDS::Edge(anEdge2->impl<TopoDS_Shape>());
+
     Handle(AIS_AngleDimension) aDim;
     if (thePrevious.get()) {
       aAISObj = thePrevious;
@@ -529,6 +540,7 @@ AISObjectPtr FeaturesPlugin_Measurement::angleDimension(AISObjectPtr thePrevious
       aDim = Handle(AIS_AngleDimension)::DownCast(aAIS);
       if (aDim.IsNull()) {
         aDim = new AIS_AngleDimension(aTEdge1, aTEdge2);
+        aAISObj = AISObjectPtr(new GeomAPI_AISObject());
         aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim));
       } else
         aDim->SetMeasuredGeometry(aTEdge1, aTEdge2);
@@ -556,12 +568,18 @@ AISObjectPtr FeaturesPlugin_Measurement::angleByPointsDimension(AISObjectPtr the
     gp_Pnt aPnt2(aPoint2->impl<gp_Pnt>());
     gp_Pnt aPnt3(aPoint3->impl<gp_Pnt>());
 
+    if (aPnt1.IsEqual(aPnt2, Precision::Confusion()) ||
+      aPnt1.IsEqual(aPnt3, Precision::Confusion()) ||
+      aPnt2.IsEqual(aPnt3, Precision::Confusion()))
+      return thePrevious;
+
     if (thePrevious.get()) {
       aAISObj = thePrevious;
       Handle(AIS_InteractiveObject) aAIS = aAISObj->impl<Handle(AIS_InteractiveObject)>();
       Handle(AIS_AngleDimension) aDim = Handle(AIS_AngleDimension)::DownCast(aAIS);
       if (aDim.IsNull()) {
         aDim = new AIS_AngleDimension(aPnt1, aPnt2, aPnt3);
+        aAISObj = AISObjectPtr(new GeomAPI_AISObject());
         aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aDim));
       } else
         aDim->SetMeasuredGeometry(aPnt1, aPnt2, aPnt3);
@@ -596,7 +614,7 @@ void FeaturesPlugin_Measurement::setupDimension(AISObjectPtr theDim)
     anAspect->SetExtensionSize((aTextSize / mySceenScale + aSize) / 2.0);
     aDim->SetDimensionAspect(anAspect);
 
-    aDim->SetZLayer(1);
+    aDim->SetZLayer(Graphic3d_ZLayerId_Top);
     std::vector<int> aColor = Config_PropManager::color("Visualization", "sketch_dimension_color");
     theDim->setColor(aColor[0], aColor[1], aColor[2]);
   }