Salome HOME
Copyright update 2020
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Measurement.cpp
index fb7d2e102e2fd3a5eeabbee8f79d589a240621dc..315f3e7070ef8396477fc2c0da319700fd373080 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+// Copyright (C) 2018-2020  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"
@@ -321,7 +320,14 @@ 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 thePrevious;
+    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();
@@ -342,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());
 
@@ -383,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 {
@@ -403,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());
@@ -447,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 {
@@ -487,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);
@@ -535,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);
@@ -573,6 +579,7 @@ AISObjectPtr FeaturesPlugin_Measurement::angleByPointsDimension(AISObjectPtr the
       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);
@@ -607,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]);
   }