Salome HOME
Fix for the issue #1321 : remove dependency on additional environment variables
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_SymbolPrs.cpp
index b66ecbd035211b72fca1adfb8ef989cb2e022c7f..ad415c53a5d75abd2f790ef593180e8200620750 100644 (file)
@@ -249,9 +249,11 @@ std::map<const char*, Handle(Image_AlienPixMap)> SketcherPrs_SymbolPrs::myIconsM
 
 SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(ModelAPI_Feature* theConstraint, 
                                              const std::shared_ptr<GeomAPI_Ax3>& thePlane)
- : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane), myIsConflicting(false)
 {
   SetAutoHilight(Standard_False);
+  myPntArray = new Graphic3d_ArrayOfPoints(1);
+  myPntArray->AddVertex(0., 0., 0.);
 }
 
 SketcherPrs_SymbolPrs::~SketcherPrs_SymbolPrs()
@@ -271,18 +273,24 @@ Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
     return myIconsMap[iconName()];
   }
   // Load icon for the presentation
-  char* aEnv = getenv("NEWGEOM_ROOT_DIR");
-  if (aEnv != NULL) {
-    TCollection_AsciiString aFile(aEnv);
-    aFile+=FSEP;
-    aFile+="resources";
-    aFile += FSEP;
-    aFile += iconName();
-    Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap();
-    if (aPixMap->Load(aFile)) {
-      myIconsMap[iconName()] = aPixMap;
-      return aPixMap;
-    }
+  std::string aFile;
+  char* anEnv = getenv("SHAPER_ROOT_DIR");
+  if (anEnv) {
+    aFile = std::string(anEnv);
+  } else {
+    anEnv = getenv("OPENPARTS_ROOT_DIR");
+    if (anEnv)
+      aFile = std::string(anEnv);
+  }
+  aFile += FSEP;
+  aFile += "resources";
+
+  aFile += FSEP;
+  aFile += iconName();
+  Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap();
+  if (aPixMap->Load(aFile.c_str())) {
+    myIconsMap[iconName()] = aPixMap;
+    return aPixMap;
   }
   // The icon for constraint is not found
   static const char aMsg[] = "Error! constraint images are not found";
@@ -364,9 +372,10 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)&
   }
 
   // Update points with default shift value
-  if (!updatePoints(20)) {
-    return;
-  }
+  // it updates array of points if the presentation is ready to display, or the array of points
+  // contains the previous values
+  
+  bool aReadyToDisplay = updateIfReadyToDisplay(20);
 
   int aNbVertex = myPntArray->VertexNumber();
   if (myOwner.IsNull()) {
@@ -398,12 +407,16 @@ void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)&
   // Disable frustum culling for this object by marking it as mutable
   aGroup->Structure()->SetMutable(true);
   //aGroup->AddPrimitiveArray(myPntArray);
+
+  if (!aReadyToDisplay)
+    SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+                          "An empty AIS presentation: SketcherPrs_LengthDimension");
 }
 
 
 
 void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
-                                            const Standard_Integer aMode)
+                                             const Standard_Integer aMode)
 {
   ClearSelected();
   if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) {
@@ -412,9 +425,31 @@ void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)&
   }
 }
 
+void SketcherPrs_SymbolPrs::SetConflictingConstraint(const bool& theConflicting,
+                                                     const std::vector<int>& theColor)
+{
+  if (theConflicting)
+  {
+    if (!myAspect.IsNull())
+      myAspect->SetColor (Quantity_Color (theColor[0] / 255., theColor[1] / 255., theColor[2] / 255.,
+                          Quantity_TOC_RGB));
+    myIsConflicting = true;
+  }
+  else
+  {
+    if (!myAspect.IsNull())
+      myAspect->SetColor (Quantity_Color (1.0, 1.0, 0.0, Quantity_TOC_RGB));
+    myIsConflicting = false;
+  }
+}
 
 void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
 {
+  // this method is a combination of OCCT OpenGL functions. The main purpose is to have
+  // equal distance from the source object to symbol indpendently of zoom.
+  // It is base on OCCT 6.9.1 and might need changes when using later OCCT versions.
+  // The specific SHAPER modifications are marked by ShaperModification:start/end, other is OCCT code
+
   // do not update presentation for invalid or already removed objects: the presentation
   // should be removed soon
   if (!myConstraint->data().get() || !myConstraint->data()->isValid())
@@ -424,10 +459,12 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace)
   const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
   Handle(OpenGl_View) aView = theWorkspace->ActiveView();
   
+  // ShaperModification:start
   double aScale = aView->Camera()->Scale();
   // Update points coordinate taking the viewer scale into account
-  if (!updatePoints(MyDist * aScale))
-    return;
+  updateIfReadyToDisplay(MyDist * aScale);
+
+  // ShaperModification:end
 
   Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes();
 
@@ -447,7 +484,10 @@ void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace)
   const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes(aCtx);
       
   if (!aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) {
-    const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0;
+    // ShaperModification:start : filling the presentation with color if there is a conflict
+    const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0 || myIsConflicting;
+    // ShaperModification:end
+
     const Handle(OpenGl_PointSprite)& aSprite = (toHilight && anAspectMarker->SpriteHighlightRes(aCtx)->IsValid())
                                               ? anAspectMarker->SpriteHighlightRes(aCtx)
                                               : aSpriteNorm;