0030820: Draw Harness, ViewerTest - vsetcolor has no effect on objects created by...
authortiv <tiv@opencascade.com>
Tue, 2 Jul 2019 16:53:20 +0000 (19:53 +0300)
committerapn <apn@opencascade.com>
Thu, 4 Jul 2019 16:34:27 +0000 (19:34 +0300)
MyPArrayObject class (an interactive object representing some array of primitives) is improved: a possibility of color changing is added to it.

src/ViewerTest/ViewerTest_ObjectCommands.cxx

index 1f88123..1c1e106 100644 (file)
@@ -3344,6 +3344,10 @@ public:
 
   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
 
+  //! Sets color to this interactive object
+  //! @param theColor the color to be set
+  virtual void SetColor (const Quantity_Color& theColor) Standard_OVERRIDE;
+
 private:
 
   void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
@@ -3359,6 +3363,13 @@ private:
                           Standard_Integer theArgCount,
                           Standard_Integer theMaxArgs);
 
+  //! Sets color for the shading aspect of the drawer used in this interactive object
+  //! @param theColor the color to be set
+  void setColorForShadingAspect(const Quantity_Color& theColor);
+
+  //! Replaces shading aspect from myDrawer->Link() with the own shading aspect of myDrawer for this interactive object
+  void replaceShadingAspect();
+
 protected:
 
   Handle(Graphic3d_AspectMarker3d) myMarkerAspect;
@@ -3584,6 +3595,21 @@ Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimTyp
   return Standard_True;
 }
 
+//=======================================================================
+// function : SetColor
+// purpose  :
+//=======================================================================
+void MyPArrayObject::SetColor (const Quantity_Color& theColor)
+{
+  AIS_InteractiveObject::SetColor (theColor);
+  setColorForShadingAspect (theColor);
+  if (myMarkerAspect)
+  {
+    myMarkerAspect->SetColor (theColor);
+  }
+  SynchronizeAspects();
+}
+
 void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
                                        const Standard_Integer theMode)
 {
@@ -3660,6 +3686,34 @@ bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand
   return true;
 }
 
+//=======================================================================
+// function : setColorForShadingAspect
+// purpose  :
+//=======================================================================
+void MyPArrayObject::setColorForShadingAspect (const Quantity_Color& theColor)
+{
+  if (myDrawer->SetupOwnShadingAspect())
+  {
+    replaceShadingAspect();
+  }
+  myDrawer->ShadingAspect()->SetColor (theColor);
+}
+
+//=======================================================================
+// function : replaceShadingAspect
+// purpose  :
+//=======================================================================
+void MyPArrayObject::replaceShadingAspect()
+{
+  if (!myDrawer->Link())
+  {
+    return;
+  }
+  Graphic3d_MapOfAspectsToAspects anAspectReplacementMap;
+  anAspectReplacementMap.Bind (myDrawer->Link()->ShadingAspect()->Aspect(), myDrawer->ShadingAspect()->Aspect());
+  replaceAspects (anAspectReplacementMap);
+}
+
 //=============================================================================
 //function : VDrawPArray
 //purpose  : Draws primitives array from list of vertexes, bounds, edges