Salome HOME
Get rid of compilation warnings. Part II. MSVC warnings.
[modules/shaper.git] / src / GeomAPI / GeomAPI_AISObject.cpp
index 74c1e1344d81dc480eccc437576e87e86785fb4d..0cf6c079fc5c54e69d6d380a5c34635619fac06e 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAPI_AISObject.cpp
-// Created:     25 Jun 2014
-// Author:      Artem ZHIDKOV
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <GeomAPI_AISObject.h>
 
@@ -44,7 +57,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,10 +88,11 @@ 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.));
+    aDrawer->SetIsoOnPlane(false);
     setImpl(new Handle(AIS_InteractiveObject)(aShape));
   }
 }
@@ -91,12 +105,11 @@ std::shared_ptr<GeomAPI_Shape> GeomAPI_AISObject::getShape() const
   if (!anAIS.IsNull()) {
     Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
     if (aShapeAIS) {
-      std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+      aResult.reset(new GeomAPI_Shape);
       aResult->setImpl(new TopoDS_Shape(aShapeAIS->Shape()));
-      return aResult;
     }
   }
-  return std::shared_ptr<GeomAPI_Shape>();
+  return aResult;
 }
 
 void GeomAPI_AISObject::createDistance(std::shared_ptr<GeomAPI_Pnt> theStartPoint,
@@ -181,7 +194,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 +329,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 +374,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;
 }
 
@@ -368,7 +387,8 @@ void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
   if (anAIS.IsNull())
     return;
 
-  Quantity_Color aColor = anAIS->Color();
+  Quantity_Color aColor;
+  anAIS->Color(aColor);
   theR = (int)(aColor.Red()*255.);
   theG = (int)(aColor.Green()*255.);
   theB = (int)(aColor.Blue()*255.);
@@ -379,13 +399,24 @@ bool GeomAPI_AISObject::setDeflection(const double theDeflection)
   bool isModified = false;
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
   if (!anAIS.IsNull()) {
-    Handle(Prs3d_Drawer) aDrawer = anAIS->Attributes();
-    if (fabs(aDrawer->DeviationCoefficient() - theDeflection) > Precision::Confusion()) {
-      aDrawer->SetDeviationCoefficient(theDeflection);
-      isModified = true;
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!anAISShape.IsNull()) {
+      Standard_Real aCoefficient, aPreviousCoefficient;
+      anAISShape->OwnDeviationCoefficient(aCoefficient, aPreviousCoefficient);
+      if (fabs(aCoefficient-theDeflection) > Precision::Confusion()) {
+        isModified = true;
+        anAISShape->SetOwnDeviationCoefficient(theDeflection);
+        Handle(Prs3d_Drawer) aDrawer = anAISShape->DynamicHilightAttributes();
+        if (!aDrawer.IsNull()) {
+          aDrawer->SetDeviationCoefficient(theDeflection);
+        }
+        // redisplay is necessary here to update presentation in all modes
+        // Standard True flag. Displayer uses Standard False flag. If it will be changed in
+        // displayer, redisplay here will not be necessary. But performance should be checked.
+        anAISShape->Redisplay(Standard_True);
+      }
     }
   }
-
   return isModified;
 }
 
@@ -401,6 +432,39 @@ double GeomAPI_AISObject::getDeflection() const
   return aDeflection;
 }
 
+bool GeomAPI_AISObject::setTransparency(const double theTransparency)
+{
+  bool isModified = false;
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!anAISShape.IsNull()) {
+      Standard_Real aPreviousValue = anAISShape->Transparency();
+      if (fabs(aPreviousValue - theTransparency) > Precision::Confusion()) {
+        anAISShape->SetTransparency(theTransparency);
+        //>SetOwnDeviationCoefficient(theTransparency);
+        isModified = true;
+        // redisplay is necessary here to update presentation in all modes
+        // Standard True flag. Displayer uses Standard False flag. If it will be changed in
+        // displayer, redisplay here will not be necessary. But performance should be checked.
+        anAISShape->Redisplay(Standard_True);
+      }
+    }
+  }
+  return isModified;
+}
+
+double GeomAPI_AISObject::getTransparency() const
+{
+  double aTransparency = 0;
+
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (!anAIS.IsNull()) {
+    aTransparency = anAIS->Transparency();
+  }
+  return aTransparency;
+}
+
 
 bool GeomAPI_AISObject::empty() const
 {
@@ -457,13 +521,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;