Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Polyline.cxx
index edc05ccc6b6b5dda2a1f2f6d1f0587e67f59e912..0119af16d3f9341e11ac1721549001fb5a3bee3d 100644 (file)
@@ -62,12 +62,28 @@ Handle( Graphic3d_ArrayOfPolylines ) BuildEdgePresentation( const TopoDS_Edge& t
   return anArray;
 }
 
+bool HYDROGUI_Polyline::GetColorOfSubShape(const TopoDS_Shape& SubShape, Quantity_Color& outColor)
+{
+  for (int i=1; i<=myShapeToColor.Extent();i++)
+  {
+    const TopoDS_Shape& aCurShape = myShapeToColor.FindKey(i);
+    TopTools_IndexedMapOfShape aSubShMap;
+    TopExp::MapShapes(aCurShape, aSubShMap);
+    if (aSubShMap.Contains(SubShape))
+    {
+      outColor = myShapeToColor(i);
+      return true;
+    }
+  }
+  return false;
+}
+
 void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
                             const Handle(Prs3d_Presentation)& aPrs,
                             const Standard_Integer aMode)
 {  
   //AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
-  //return;
+  // return;
 
   aPrs->Clear();
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
@@ -78,7 +94,6 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
   anWidth =2;
   Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth );
 
-  TopExp_Explorer Exp1 ( myshape, TopAbs_EDGE );
   Bnd_Box BB;
   BRepBndLib::AddClose(myshape, BB);
   double xmin, xmax, ymin, ymax, zmin, zmax;
@@ -89,14 +104,27 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
     double minSide = Min(Abs(xmax - xmin), Abs(ymax - ymin));
     devCoeff = minSide > 50 ? 0.05 : minSide / 3000;
   }
-  for ( ; Exp1.More(); Exp1.Next() )
+
+  TopExp_Explorer Exp ( myshape, TopAbs_WIRE );
+  for ( ; Exp.More(); Exp.Next() )
   {
-    TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() );
-    Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, devCoeff );
-    if( !anArray.IsNull() )
+    TopoDS_Shape W = Exp.Current();
+    TopExp_Explorer Exp1 (W, TopAbs_EDGE );
+    Quantity_Color aWCol = aColor; //from drawer
+    if (myShapeToColor.Contains(W))
+    {
+      Quantity_Color aWCol = myShapeToColor.FindFromKey(W);
+      anAspect = new Graphic3d_AspectLine3d( aWCol, aType, anWidth );
+    }
+    for ( ; Exp1.More(); Exp1.Next() )
     {
-      aGroup->SetPrimitivesAspect( anAspect );
-      aGroup->AddPrimitiveArray( anArray );
+      TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() );
+      Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, devCoeff);
+      if( !anArray.IsNull() )
+      {
+        aGroup->SetPrimitivesAspect( anAspect );
+        aGroup->AddPrimitiveArray( anArray );
+      }
     }
   }
 }
@@ -107,7 +135,8 @@ QList<Handle(AIS_InteractiveObject)> HYDROGUI_Polyline::createPresentations
   QList<Handle(AIS_InteractiveObject)> shapes;
 
   // 1. Main shape
-  shapes.append( new HYDROGUI_Polyline( theShape ) );
+  Handle(HYDROGUI_Polyline) aMPoly = new HYDROGUI_Polyline( theShape );
+  shapes.append( aMPoly );
 
   // 2. Shapes for direction arrows on edges
   TopExp_Explorer Exp ( theShape, TopAbs_EDGE );
@@ -116,7 +145,7 @@ QList<Handle(AIS_InteractiveObject)> HYDROGUI_Polyline::createPresentations
     TopoDS_Edge anEdge = TopoDS::Edge(Exp.Current());
     if ( !anEdge.IsNull() ) 
     {
-      Handle(HYDROGUI_Arrow) arrow = new HYDROGUI_Arrow( anEdge );
+      Handle(HYDROGUI_Arrow) arrow = new HYDROGUI_Arrow( anEdge, aMPoly );
       if( theType>=0 )
         arrow->SetType( (HYDROGUI_Arrow::Type)theType );
       if( theSize>=0 )
@@ -149,8 +178,8 @@ void HYDROGUI_Polyline::update( const QList<Handle(AIS_InteractiveObject)>& theO
 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Arrow, AIS_Shape)
 
 
-HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge )
-  : AIS_Shape( edge ), myType( Cone ), mySize( 35 )
+  HYDROGUI_Arrow::HYDROGUI_Arrow( const TopoDS_Edge& edge, const Handle(HYDROGUI_Polyline)& polyline )
+  : AIS_Shape( edge ), myType( Cone ), mySize( 35 ), myParentPoly (polyline)
 {
 }
 
@@ -178,6 +207,11 @@ void HYDROGUI_Arrow::SetSize( int theSize )
   mySize = qMax( theSize, 0 );
 }
 
+const Handle(HYDROGUI_Polyline)& HYDROGUI_Arrow::getParentPolyline() const
+{
+  return myParentPoly;
+}
+
 void HYDROGUI_Arrow::BoundingBox (Bnd_Box& theBndBox)
 {
   //Nothing to change, we consider arrow as object with empty bounding box
@@ -239,6 +273,9 @@ void HYDROGUI_Arrow::Compute( const Handle(PrsMgr_PresentationManager3d)& aPrese
   Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth );
   anWidth = 1;
 
+  const Handle(HYDROGUI_Polyline)& aParentPoly = getParentPolyline();
+  aParentPoly->GetColorOfSubShape(anEdge, aColor);
+
   if( myType==Cone )
   {
     Handle(Graphic3d_AspectLine3d) anAspect = new Graphic3d_AspectLine3d( aColor, aType, anWidth );