Salome HOME
Issue #2059 point in sketch is created not on selected line of external sketchPlane...
[modules/shaper.git] / src / GeomAPI / GeomAPI_AISObject.cpp
index bc6aa29a49c0e3ad432790cdc30b10d72b3d3cf0..8a3852baaf49ccff4263c87bdf511a44d6f71c16 100644 (file)
@@ -44,7 +44,7 @@ GeomAPI_AISObject::GeomAPI_AISObject()
 GeomAPI_AISObject::~GeomAPI_AISObject()
 {
   if (!empty()) {
-    // This is necessary for correct deletion of Handle entity. 
+    // This is necessary for correct deletion of Handle entity.
     // Without this Handle does not decremented counter to 0
     Handle(AIS_InteractiveObject) *anAIS = implPtr<Handle(AIS_InteractiveObject)>();
     anAIS->Nullify();
@@ -75,7 +75,7 @@ void GeomAPI_AISObject::createShape(std::shared_ptr<GeomAPI_Shape> theShape)
     // Set default point as a '+' symbol
     Handle(AIS_Shape) aShape = new AIS_Shape(aTDS);
     Handle(Prs3d_Drawer) aDrawer = aShape->Attributes();
-    if (aDrawer->HasOwnPointAspect()) 
+    if (aDrawer->HasOwnPointAspect())
       aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
     else
       aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
@@ -181,7 +181,7 @@ void GeomAPI_AISObject::createRadius(std::shared_ptr<GeomAPI_Circ> theCircle,
   // TODO: a bug in AIS_RadiusDimension:
   // The anchor point can't be myCirc.Location() - an exception is raised.
   // But we need exactly this case...
-  // We want to show a radius dimension starting from the circle centre and 
+  // We want to show a radius dimension starting from the circle centre and
   // ending at the user-defined point.
   // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all.
   std::shared_ptr<GeomAPI_Pnt> anAnchor = theCircle->project(theFlyoutPoint);
@@ -316,7 +316,10 @@ void GeomAPI_AISObject::setColor(const int& theColor)
     aDimAIS->DimensionAspect()->SetCommonColor(aColor);
   }
   Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
-  aContext->SetColor(anAIS, aColor, false);
+  if (!aContext.IsNull())
+    aContext->SetColor(anAIS, aColor, false);
+  else
+    anAIS->SetColor(aColor);
 }
 
 double GeomAPI_AISObject::width()
@@ -358,7 +361,10 @@ bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
     aDimAIS->DimensionAspect()->SetCommonColor(aColor);
   }
   Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
-  aContext->SetColor(anAIS, aColor, false);
+  if (!aContext.IsNull())
+    aContext->SetColor(anAIS, aColor, false);
+  else
+    anAIS->SetColor(aColor);
   return true;
 }
 
@@ -464,13 +470,13 @@ bool GeomAPI_AISObject::setLineStyle(int theStyle)
     if (aDrawer->HasOwnWireAspect()) {
       aLineAspect = aDrawer->WireAspect();
     }
-    Quantity_Color aCurrentColor;
-    Aspect_TypeOfLine aCurrentType;
-    Standard_Real aCurrentWidth;
-    aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth);
-    isChanged = aType != aCurrentType;
-    if (isChanged) {
-      aLineAspect->SetTypeOfLine(aType);
+    if (!aLineAspect.IsNull()) {
+      Handle(Graphic3d_AspectLine3d) aGraphicAspect = aLineAspect->Aspect();
+      Aspect_TypeOfLine aCurrentType = aGraphicAspect->Type();
+      isChanged = aType != aCurrentType;
+      if (isChanged) {
+        aLineAspect->SetTypeOfLine(aType);
+      }
     }
   }
   return isChanged;