Salome HOME
Regression: do not rotate viewer if sketch plane is selected from a face of a shape
[modules/shaper.git] / src / GeomAPI / GeomAPI_AISObject.cpp
index 2365746655bf4d095c096c00aae855a4a703e0ad..198a1892631ded1ab512bfaaf282d6f7b9473160 100644 (file)
@@ -71,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,
@@ -133,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)
@@ -272,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);
@@ -305,7 +343,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);
@@ -343,7 +380,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;
@@ -403,6 +442,8 @@ bool GeomAPI_AISObject::setTransparensy(double theVal)
       isChanged = aCurrentValue != theVal;
       if (isChanged)
         aContext->SetTransparency(anAIS, theVal, false);
+    } else {
+      anAIS->SetTransparency(theVal);
     }
   }
  return isChanged;