Salome HOME
Merge branch 'BR_1328' into BR_DEMO
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Polyline.cxx
index 91e0a06ab5c10de7e1653de9b4776db9f950ce4c..b9a7a2aacb62ab1c041395bc3438460992192639 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  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
@@ -26,6 +22,7 @@
 #include <BRep_Tool.hxx>
 #include <GCPnts_AbscissaPoint.hxx>
 #include <GeomAdaptor_Curve.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
 #include <gp_Pnt.hxx>
 #include <gp_Dir.hxx>
 #include <Prs3d_Arrow.hxx>
@@ -44,7 +41,6 @@
 #include <BRepAdaptor_Curve.hxx>
 #include <Prs3d_LineAspect.hxx>
 
-IMPLEMENT_STANDARD_HANDLE (HYDROGUI_Polyline, AIS_Shape)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROGUI_Polyline, AIS_Shape)
 
 
@@ -82,16 +78,33 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
 
   aPrs->Clear();
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( aPrs );
-  Handle(Graphic3d_AspectLine3d) anAspect = Attributes()->FaceBoundaryAspect()->Aspect();
-  aGroup->SetGroupPrimitivesAspect( anAspect );
+  Quantity_Color aColor;
+  Aspect_TypeOfLine aType;
+  Standard_Real anWidth;
+  Attributes()->LineAspect()->Aspect()->Values( aColor, aType, anWidth );
+  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;
+  double devCoeff = 0.05;
+  if (!BB.IsVoid())
+  {
+    BB.Get(xmin, ymin, zmin, xmax, ymax, zmax); //ignore Z coord
+    double minSide = Min(Abs(xmax - xmin), Abs(ymax - ymin));
+    devCoeff = minSide > 50 ? 0.05 : minSide / 3000;
+  }
   for ( ; Exp1.More(); Exp1.Next() )
   {
     TopoDS_Edge anEdge = TopoDS::Edge( Exp1.Current() );
-    Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, 0.1 );
+    Handle( Graphic3d_ArrayOfPolylines ) anArray = BuildEdgePresentation( anEdge, devCoeff );
     if( !anArray.IsNull() )
-      aGroup->AddPrimitiveArray ( anArray );
+    {
+      aGroup->SetPrimitivesAspect( anAspect );
+      aGroup->AddPrimitiveArray( anArray );
+    }
   }
 
    
@@ -150,7 +163,8 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
     
     gp_Pnt aPnt1 = C->Value (aMaxRatioStep);
     gp_Vec aDir;
-    if (!UseD1) {
+    if (!UseD1) 
+    {
       GCPnts_AbscissaPoint aAbsPoint(aAdC, -aArrLen, aMaxRatioStep);
       double aParam = aAbsPoint.Parameter();      
       gp_Pnt aPnt2 = C->Value (aParam);
@@ -158,7 +172,8 @@ void HYDROGUI_Polyline::Compute(const Handle(PrsMgr_PresentationManager3d)& aPre
       D.Subtract (aPnt2.XYZ());
       aDir = D;
     }
-    else
+
+    if (UseD1 || aDir.IsEqual (gp_Vec(0,0,0), Precision::Confusion(), Precision::Angular()))
       C->D1(aMaxRatioStep, aPnt1, aDir);
   
     if ( anEdge.Orientation() == TopAbs_REVERSED )