0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_Circle.cxx
index 14d653c..78239a1 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-
 #include <AIS_Circle.hxx>
+
 #include <AIS_GraphicTool.hxx>
 #include <Aspect_TypeOfLine.hxx>
 #include <GC_MakeArcOfCircle.hxx>
 #include <Geom_Circle.hxx>
-#include <Geom_Transformation.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Graphic3d_Structure.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_LineAspect.hxx>
 #include <Prs3d_Presentation.hxx>
-#include <Prs3d_Projector.hxx>
 #include <Quantity_Color.hxx>
 #include <Select3D_SensitiveCircle.hxx>
 #include <SelectMgr_EntityOwner.hxx>
@@ -85,19 +83,6 @@ void AIS_Circle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresenta
 
 }
 
-//=======================================================================
-//function : Compute
-//purpose  : 
-//=======================================================================
-
-void AIS_Circle::Compute(const Handle(Prs3d_Projector)& aProjector,
-                         const Handle(Geom_Transformation)& aTransformation,
-                         const Handle(Prs3d_Presentation)& aPresentation)
-{
-// Standard_NotImplemented::Raise("AIS_Circle::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
-  PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
-}
-
 //=======================================================================
 //function : ComputeSelection
 //purpose  : 
@@ -112,15 +97,27 @@ void AIS_Circle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
 
 }
 
-
 //=======================================================================
-//function : SetColor
-//purpose  : 
+//function : replaceWithNewLineAspect
+//purpose  :
 //=======================================================================
-
-void AIS_Circle::SetColor(const Quantity_NameOfColor aCol)
+void AIS_Circle::replaceWithNewLineAspect (const Handle(Prs3d_LineAspect)& theAspect)
 {
-  SetColor(Quantity_Color(aCol));
+  if (!myDrawer->HasLink())
+  {
+    myDrawer->SetLineAspect (theAspect);
+    return;
+  }
+
+  const Handle(Graphic3d_AspectLine3d) anAspectOld = myDrawer->LineAspect()->Aspect();
+  const Handle(Graphic3d_AspectLine3d) anAspectNew = !theAspect.IsNull() ? theAspect->Aspect() : myDrawer->Link()->LineAspect()->Aspect();
+  if (anAspectNew != anAspectOld)
+  {
+    myDrawer->SetLineAspect (theAspect);
+    Graphic3d_MapOfAspectsToAspects aReplaceMap;
+    aReplaceMap.Bind (anAspectOld, anAspectNew);
+    replaceAspects (aReplaceMap);
+  }
 }
 
 //=======================================================================
@@ -133,34 +130,41 @@ void AIS_Circle::SetColor(const Quantity_Color &aCol)
   hasOwnColor=Standard_True;
   myDrawer->SetColor (aCol);
 
-  Standard_Real WW = HasWidth() ? myOwnWidth :
-                                  myDrawer->HasLink() ?
-                                  AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
-                                  1.;
-
-  if (!myDrawer->HasOwnLineAspect ())
-    myDrawer->SetLineAspect (new Prs3d_LineAspect(aCol,Aspect_TOL_SOLID,WW));
+  if (!myDrawer->HasOwnLineAspect())
+  {
+    Standard_Real WW = HasWidth() ? myOwnWidth :
+                                    myDrawer->HasLink() ?
+                                    AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_Line) :
+                                    1.;
+    replaceWithNewLineAspect (new Prs3d_LineAspect (aCol, Aspect_TOL_SOLID, WW));
+  }
   else
+  {
     myDrawer->LineAspect()->SetColor(aCol);
+    SynchronizeAspects();
+  }
 }
 
-
-
 //=======================================================================
 //function : SetWidth 
 //purpose  : 
 //=======================================================================
 void AIS_Circle::SetWidth(const Standard_Real aValue)
 {
-  myOwnWidth=aValue;
+  myOwnWidth = (Standard_ShortReal )aValue;
 
-  if (!myDrawer->HasOwnLineAspect ()) {
+  if (!myDrawer->HasOwnLineAspect())
+  {
     Quantity_Color CC = Quantity_NOC_YELLOW;
     if( HasColor() ) CC = myDrawer->Color();
     else if(myDrawer->HasLink()) AIS_GraphicTool::GetLineColor (myDrawer->Link(), AIS_TOA_Line, CC);
-    myDrawer->SetLineAspect (new Prs3d_LineAspect(CC,Aspect_TOL_SOLID,aValue));
-  } else
+    replaceWithNewLineAspect (new Prs3d_LineAspect (CC, Aspect_TOL_SOLID, aValue));
+  }
+  else
+  {
     myDrawer->LineAspect()->SetWidth(aValue);
+    SynchronizeAspects();
+  }
 }
 
 
@@ -172,15 +176,18 @@ void AIS_Circle::UnsetColor()
 {
   hasOwnColor = Standard_False;
 
-  Handle(Prs3d_LineAspect) NullAsp;
-
-  if (!HasWidth()) myDrawer->SetLineAspect(NullAsp);
-  else{
-    Quantity_Color CC = Quantity_NOC_YELLOW;;
+  if (!HasWidth())
+  {
+    replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
+  }
+  else
+  {
+    Quantity_Color CC = Quantity_NOC_YELLOW;
     if( HasColor() ) CC = myDrawer->Color();
     else if (myDrawer->HasLink()) AIS_GraphicTool::GetLineColor(myDrawer->Link(),AIS_TOA_Line,CC);
     myDrawer->LineAspect()->SetColor(CC);
     myDrawer->SetColor (CC);
+    SynchronizeAspects();
   }
 }
 
@@ -190,11 +197,13 @@ void AIS_Circle::UnsetColor()
 //=======================================================================
 void AIS_Circle::UnsetWidth()
 {
-  Handle(Prs3d_LineAspect) NullAsp;
-
-  if (!HasColor()) myDrawer->SetLineAspect(NullAsp);
-  else{
-   Standard_Real WW = myDrawer->HasLink() ? AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.;
+  if (!HasColor())
+  {
+    replaceWithNewLineAspect (Handle(Prs3d_LineAspect)());
+  }
+  else
+  {
+   Standard_ShortReal WW = myDrawer->HasLink() ? (Standard_ShortReal )AIS_GraphicTool::GetLineWidth(myDrawer->Link(),AIS_TOA_Line) : 1.0f;
    myDrawer->LineAspect()->SetWidth(WW);
    myOwnWidth = WW;
   }
@@ -238,7 +247,7 @@ void AIS_Circle::ComputeCircleSelection(const Handle(SelectMgr_Selection)& aSele
 {
   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
-                                                                       myComponent,
+                                                                       myComponent->Circ(),
                                                                        myIsFilledCircleSens);
   aSelection->Add(seg);
 }
@@ -253,17 +262,8 @@ void AIS_Circle::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelecti
 
   Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
   Handle(Select3D_SensitiveCircle) seg = new Select3D_SensitiveCircle (eown,
-                                                                       myComponent,
+                                                                       myComponent->Circ(),
                                                                        myUStart, myUEnd,
                                                                        myIsFilledCircleSens);
   aSelection->Add(seg);
 }
-
-//=======================================================================
-//function : Compute
-//purpose  : to avoid warning
-//=======================================================================
-void AIS_Circle::Compute(const Handle(Prs3d_Projector)&, 
-                         const Handle(Prs3d_Presentation)&)
-{
-}