Salome HOME
Update movement of a circle
[modules/shaper.git] / src / GeomAPI / GeomAPI_AISObject.cpp
index 8f053f7cf90a838a5741d17fb442dc9d6e85ee29..3f7646688b80eab7f6c9736522d5c8b05eec0de3 100644 (file)
@@ -41,6 +41,17 @@ GeomAPI_AISObject::GeomAPI_AISObject()
 {
 }
 
+GeomAPI_AISObject::~GeomAPI_AISObject()
+{
+  if (!empty()) {
+    // 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();
+  }
+}
+
+
 void GeomAPI_AISObject::createShape(std::shared_ptr<GeomAPI_Shape> theShape)
 {
   const TopoDS_Shape& aTDS =
@@ -60,8 +71,32 @@ void GeomAPI_AISObject::createShape(std::shared_ptr<GeomAPI_Shape> theShape)
       aShapeAIS->Set(aTDS);
       aShapeAIS->Redisplay(Standard_True);
     }
-  } else
-    setImpl(new Handle(AIS_InteractiveObject)(new AIS_Shape(aTDS)));
+  } else {
+    // Set default point as a '+' symbol
+    Handle(AIS_Shape) aShape = new AIS_Shape(aTDS);
+    Handle(Prs3d_Drawer) aDrawer = aShape->Attributes();
+    if (aDrawer->HasOwnPointAspect()) 
+      aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
+    else
+      aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
+    setImpl(new Handle(AIS_InteractiveObject)(aShape));
+  }
+}
+
+std::shared_ptr<GeomAPI_Shape> GeomAPI_AISObject::getShape() const
+{
+  std::shared_ptr<GeomAPI_Shape> aResult;
+
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+    if (aShapeAIS) {
+      std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+      aResult->setImpl(new TopoDS_Shape(aShapeAIS->Shape()));
+      return aResult;
+    }
+  }
+  return std::shared_ptr<GeomAPI_Shape>();
 }
 
 void GeomAPI_AISObject::createDistance(std::shared_ptr<GeomAPI_Pnt> theStartPoint,
@@ -122,6 +157,21 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr<GeomAPI_Pnt> theStartPoin
   }
 }
 
+bool GeomAPI_AISObject::isEmptyDistanceGeometry()
+{
+  bool anEmpty = false;
+
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
+    if (!aDimAIS.IsNull()) {
+      anEmpty = !aDimAIS->IsValid();
+    }
+  }
+
+  return anEmpty;
+}
+
 void GeomAPI_AISObject::createRadius(std::shared_ptr<GeomAPI_Circ> theCircle,
                                      std::shared_ptr<GeomAPI_Pnt> theFlyoutPoint,
                                      double theRadius)
@@ -261,7 +311,6 @@ void GeomAPI_AISObject::setColor(const int& theColor)
   if (anAIS.IsNull())
     return;
   Quantity_Color aColor((Quantity_NameOfColor) theColor);
-  anAIS->SetColor(aColor);
   Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
   if (!aDimAIS.IsNull()) {
     aDimAIS->DimensionAspect()->SetCommonColor(aColor);
@@ -270,6 +319,16 @@ void GeomAPI_AISObject::setColor(const int& theColor)
   aContext->SetColor(anAIS, aColor, false);
 }
 
+double GeomAPI_AISObject::width()
+{
+  double aWidth = 0.0;
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    aWidth = anAIS->Width();
+  }
+  return aWidth;
+}
+
 bool GeomAPI_AISObject::setWidth(const double& theWidth)
 {
   bool isChanged = false;
@@ -294,7 +353,6 @@ bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
   if (aColor.IsEqual(aCurrentColor))
     return false;
 
-  anAIS->SetColor(aColor);
   Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
   if (!aDimAIS.IsNull()) {
     aDimAIS->DimensionAspect()->SetCommonColor(aColor);
@@ -332,7 +390,9 @@ int GeomAPI_AISObject::getShapeType() const
   if (!anAIS.IsNull()) {
     Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anAIS);
     if (!aAISShape.IsNull()) {
-      return aAISShape->Shape().ShapeType();
+      const TopoDS_Shape aShape = aAISShape->Shape();
+      if (!aShape.IsNull())
+        return aShape.ShapeType();
     }
   }
   return -1;
@@ -342,8 +402,8 @@ void GeomAPI_AISObject::setPointMarker(int theType, double theScale)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
-    Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
-    if (aDrawer->HasPointAspect()) {
+    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+    if (aDrawer->HasOwnPointAspect()) {
       Handle(Prs3d_PointAspect) aPA = aDrawer->PointAspect();
       aPA->SetTypeOfMarker((Aspect_TypeOfMarker)theType);
       aPA->SetScale(theScale);
@@ -359,14 +419,14 @@ bool GeomAPI_AISObject::setLineStyle(int theStyle)
   bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
-    Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
+    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
     Handle(Prs3d_LineAspect) aLineAspect;
 
     Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle;
-    if (aDrawer->HasLineAspect()) {
+    if (aDrawer->HasOwnLineAspect()) {
       aLineAspect = aDrawer->LineAspect();
     }
-    if (aDrawer->HasWireAspect()) {
+    if (aDrawer->HasOwnWireAspect()) {
       aLineAspect = aDrawer->WireAspect();
     }
     Quantity_Color aCurrentColor;
@@ -381,7 +441,6 @@ bool GeomAPI_AISObject::setLineStyle(int theStyle)
   return isChanged;
 }
 
-
 bool GeomAPI_AISObject::setTransparensy(double theVal)
 {
   bool isChanged = false;
@@ -393,6 +452,8 @@ bool GeomAPI_AISObject::setTransparensy(double theVal)
       isChanged = aCurrentValue != theVal;
       if (isChanged)
         aContext->SetTransparency(anAIS, theVal, false);
+    } else {
+      anAIS->SetTransparency(theVal);
     }
   }
  return isChanged;