Salome HOME
Issue #555 - Make a number of shifted/rotated copies - selected object does not appea...
[modules/shaper.git] / src / GeomAPI / GeomAPI_AISObject.cpp
index f1534e2afae88490f226be39e09c5b313f98cc5e..681926a68d3439c3235d0657e34e8bfa949167aa 100644 (file)
 #include <BRepBndLib.hxx>
 
 #include <AIS_InteractiveObject.hxx>
+#include <AIS_InteractiveContext.hxx>
 #include <AIS_LengthDimension.hxx>
 #include <AIS_ParallelRelation.hxx>
 #include <AIS_PerpendicularRelation.hxx>
 #include <AIS_RadiusDimension.hxx>
 #include <AIS_Shape.hxx>
 #include <AIS_FixRelation.hxx>
+#include <Prs3d_PointAspect.hxx>
+
+#include <Graphic3d_AspectLine3d.hxx>
 
 const double tolerance = 1e-7;
 
@@ -37,6 +41,17 @@ GeomAPI_AISObject::GeomAPI_AISObject()
 {
 }
 
+GeomAPI_AISObject::~GeomAPI_AISObject()
+{
+  if (myImpl) {
+    // This is necessary for correct deletion of Handle entity. 
+    // Without this Handle does not decremented counter to 0
+    Handle(AIS_InteractiveObject) *anAIS = (Handle(AIS_InteractiveObject)*)myImpl;
+    anAIS->Nullify();
+  }
+}
+
+
 void GeomAPI_AISObject::createShape(std::shared_ptr<GeomAPI_Shape> theShape)
 {
   const TopoDS_Shape& aTDS =
@@ -94,9 +109,9 @@ void GeomAPI_AISObject::createDistance(std::shared_ptr<GeomAPI_Pnt> theStartPoin
 
     Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
     anAspect->MakeArrows3d(Standard_False);
-    anAspect->MakeText3d(false);
+    anAspect->MakeText3d(Standard_False);
     anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
-    anAspect->MakeTextShaded(false);
+    anAspect->MakeTextShaded(Standard_True);
     anAspect->ArrowAspect()->SetLength(theDistance / 10.);
     aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
     aDimAIS->SetDimensionAspect(anAspect);
@@ -251,8 +266,6 @@ void GeomAPI_AISObject::createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
   }
 }
 
-
-
 void GeomAPI_AISObject::setColor(const int& theColor)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
@@ -264,27 +277,54 @@ void GeomAPI_AISObject::setColor(const int& theColor)
   if (!aDimAIS.IsNull()) {
     aDimAIS->DimensionAspect()->SetCommonColor(aColor);
   }
+  Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
+  aContext->SetColor(anAIS, aColor, false);
 }
 
-void GeomAPI_AISObject::setWidth(const double& theWidth)
+bool GeomAPI_AISObject::setWidth(const double& theWidth)
 {
+  bool isChanged = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
-  if (anAIS.IsNull())
-    return;
-  anAIS->SetWidth(theWidth);
+  if (!anAIS.IsNull()) {
+    isChanged = anAIS->Width() != theWidth;
+    if (isChanged)
+      anAIS->SetWidth(theWidth);
+  }
+  return isChanged;
 }
 
-void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
+bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (anAIS.IsNull())
-    return;
+    return false;
   Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB);
+  Quantity_Color aCurrentColor;
+  anAIS->Color(aCurrentColor);
+  // do not set the same color to the presentation
+  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);
   }
+  Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
+  aContext->SetColor(anAIS, aColor, false);
+  return true;
+}
+
+void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (anAIS.IsNull())
+    return;
+
+  Quantity_Color aColor = anAIS->Color();
+  theR = (int)(aColor.Red()*255.);
+  theG = (int)(aColor.Green()*255.);
+  theB = (int)(aColor.Blue()*255.);
 }
 
 bool GeomAPI_AISObject::empty() const
@@ -296,3 +336,74 @@ bool GeomAPI_AISObject::empty() const
   return false;
 }
 
+int GeomAPI_AISObject::getShapeType() const
+{
+  Handle(AIS_InteractiveObject) anAIS = const_cast<GeomAPI_AISObject*>(this)
+      ->impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!aAISShape.IsNull()) {
+      return aAISShape->Shape().ShapeType();
+    }
+  }
+  return -1;
+}
+
+void GeomAPI_AISObject::setPointMarker(int theType, double theScale)
+{
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+    if (aDrawer->HasOwnPointAspect()) {
+      Handle(Prs3d_PointAspect) aPA = aDrawer->PointAspect();
+      aPA->SetTypeOfMarker((Aspect_TypeOfMarker)theType);
+      aPA->SetScale(theScale);
+    } else {
+      Quantity_NameOfColor aCol = Quantity_NOC_YELLOW;
+      aDrawer->SetPointAspect(new Prs3d_PointAspect((Aspect_TypeOfMarker)theType, aCol, theScale));
+    }
+  }
+}
+
+bool GeomAPI_AISObject::setLineStyle(int theStyle)
+{
+  bool isChanged = false;
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
+    Handle(Prs3d_LineAspect) aLineAspect;
+
+    Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle;
+    if (aDrawer->HasOwnLineAspect()) {
+      aLineAspect = aDrawer->LineAspect();
+    }
+    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);
+    }
+  }
+  return isChanged;
+}
+
+bool GeomAPI_AISObject::setTransparensy(double theVal)
+{
+  bool isChanged = false;
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
+    if (!aContext.IsNull()) {
+      double aCurrentValue = anAIS->Transparency();
+      isChanged = aCurrentValue != theVal;
+      if (isChanged)
+        aContext->SetTransparency(anAIS, theVal, false);
+    }
+  }
+ return isChanged;
+}