]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Bug #136 - performance
authornds <nds@opencascade.com>
Mon, 2 Dec 2013 16:30:42 +0000 (16:30 +0000)
committernds <nds@opencascade.com>
Mon, 2 Dec 2013 16:30:42 +0000 (16:30 +0000)
src/HYDROCurveCreator/CurveCreator_AISCurve.cxx
src/HYDROCurveCreator/CurveCreator_AISCurve.hxx
src/HYDROCurveCreator/CurveCreator_Curve.hxx
src/HYDROCurveCreator/CurveCreator_Widget.cxx

index b6a2d60aeba7d285115252f3d0324e8c7a2f7234..dde3a4167d9b3fd0aad7535de274ade133c51a9c 100644 (file)
@@ -18,7 +18,7 @@
 //
 
 #include "CurveCreator_AISCurve.hxx"
-#include "CurveCreator_ICurve.hxx"
+#include "CurveCreator_Curve.hxx"
 
 #include <Quantity_Color.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <GeomAPI_Interpolate.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
 
+#include <Graphic3d_Array1OfVertex.hxx>
+#include <Graphic3d_Group.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Prs3d_Root.hxx>
+
 IMPLEMENT_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
 IMPLEMENT_STANDARD_RTTIEXT(CurveCreator_AISCurve, AIS_Shape)
 
-CurveCreator_AISCurve::CurveCreator_AISCurve( CurveCreator_ICurve* theCurve )
+CurveCreator_AISCurve::CurveCreator_AISCurve( CurveCreator_Curve* theCurve )
 : AIS_Shape( TopoDS_Shape() ), myCurve( theCurve )
 {
 }
 
+void CurveCreator_AISCurve::getPoint( const int theISection, const int theIPoint,
+                                      gp_Pnt& thePoint )
+{
+  double anX, anY, aZ;
+  myCurve->getCoordinates( theISection, theIPoint, anX, anY, aZ );
+  thePoint = gp_Pnt( anX, anY, aZ);
+  /*
+  double anX, anY, aZ;
+
+  std::deque<float> aPoint = myCurve->getPoint( theSectionId, thePointId );
+  anX = aPoint[0];
+  anY = aPoint[1];
+  aZ  = aPoint[2];
+  thePoint = gp_Pnt( anX, anY, aZ);*/
+}
+
+#define MAKE_BUILDER_USE
 void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)& thePM,
                                      const Handle(Prs3d_Presentation)& thePrs,
                                      const Standard_Integer theMode )
 {
   thePrs->Clear();
 
-  //AIS_Shape::Compute( thePM, thePrs, theMode );
-
   for( int iSection = 0 ; iSection < myCurve->getNbSections() ; iSection++ ) {
-    //TopoDS_Shape aShape;
     CurveCreator::SectionType aSectType = myCurve->getSectionType( iSection );
-    int aSectSize = myCurve->getNbPoints( iSection );
+    int aPointSize = myCurve->getNbPoints( iSection );
     bool aSectIsClosed = myCurve->isClosed( iSection );
-    //if( aSectType == CurveCreator::Polyline )
+    if( aSectType == CurveCreator::Polyline )
     {
-
-      /*int iPoint = 0; 
-      for( ; iPoint < ( aSectSize - 1 ) ; iPoint++ ){
-        Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
-        aSectionRepresentation.push_back( anAISPnt );
-        Handle_AIS_Line aLine = getAISLine( theISection, iPoint, iPoint+1 );
-        aSectionRepresentation.push_back( aLine );
+      int iPoint = 0;
+      gp_Pnt aPrevPoint, aPoint;
+      if ( aPointSize == 1 ) {
+        getPoint( iSection, iPoint, aPrevPoint );
+        TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
+        Set( aVertex );
       }
-      if( aSectSize != 0 ){
-        Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint); 
-        aSectionRepresentation.push_back( anAISPnt );
-        if( isClosed(theISection) && ( aSectSize > 1 ) ){
-          Handle_AIS_Line aLine = getAISLine( theISection, iPoint, 0 );
-          aSectionRepresentation.push_back( aLine );
+      else if ( aPointSize > 1 ) {
+#ifdef MAKE_BUILDER_USE
+        TopoDS_Edge aPointEdge;
+        BRepBuilderAPI_MakeWire aMakeWire;
+        getPoint( iSection, iPoint, aPrevPoint );
+        iPoint++;
+        for( ; iPoint < aPointSize; iPoint++ ) {
+          getPoint( iSection, iPoint, aPoint );
+          aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+          aMakeWire.Add( BRepBuilderAPI_MakeWire( aPointEdge ) );
+          aPrevPoint = aPoint;
         }
+        if( myCurve->isClosed( iSection ) && ( aPointSize > 2 ) ) {
+          getPoint( iSection, 0, aPoint );
+          aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+          aMakeWire.Add( BRepBuilderAPI_MakeWire( aPointEdge ) );
+        }
+
+        TopoDS_Wire aLineWire = aMakeWire.Wire();
+        Set( aLineWire );
+        AIS_Shape::Compute( thePM, thePrs, theMode );
+      }
+#else
+      bool isClosed = myCurve->isClosed( iSection ) && ( aPointSize > 2 );
+      Handle(Graphic3d_ArrayOfPolylines) anArray = new Graphic3d_ArrayOfPolylines
+                                             ( !isClosed ? aPointSize : aPointSize+1 );
+      for( ; iPoint < aPointSize; iPoint++ ) {
+        getPoint( iSection, iPoint, aPoint );
+        anArray->AddVertex(aPoint.X(), aPoint.Y(), aPoint.Z());
+      }
+
+      if( myCurve->isClosed( iSection ) && ( aPointSize > 2 ) ) {
+        getPoint( iSection, 0, aPoint );
+        anArray->AddVertex(aPoint.X(), aPoint.Y(), aPoint.Z());
       }
-      */
+      Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup( thePrs );
+      aGroup->AddPrimitiveArray(anArray);
+#endif
     }
-    //else if( aSectType == CurveCreator::Spline )
+    else if( aSectType == CurveCreator::Spline )
     {
       std::vector<double> aPoints;
-      for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
+      for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
       {
-        /*Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
-        aSectionRepresentation.push_back( anAISPnt );
-        */
         CurveCreator::Coordinates aCoords = myCurve->getPoint( iSection, iPoint );
         double aX = aCoords[0];
         double aY = aCoords[1];
@@ -87,9 +132,10 @@ void CurveCreator_AISCurve::Compute( const Handle(PrsMgr_PresentationManager3d)&
         aPoints.push_back( aX );
         aPoints.push_back( aY );
       }
-      if( aSectSize > 1 )
+      if( aPointSize > 1 )
       {
         Handle(Geom_BSplineCurve) aBSplineCurve;
+        Handle(Geom_Curve) aGeomCurve;
         // fill array for algorithm by the received coordinates
         int aLen = aPoints.size() / 2;
         Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
index 292e77c077edfe696913b6235544262724ae692b..5c01627e946ec3e2a032b602afe7ff7041e2c034 100644 (file)
@@ -26,8 +26,9 @@
 #include <Standard_DefineHandle.hxx>   
 
 #include <AIS_Shape.hxx>
+#include <gp_Pnt.hxx>
 
-class CurveCreator_ICurve;
+class CurveCreator_Curve;
 
 DEFINE_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
 
@@ -38,7 +39,7 @@ DEFINE_STANDARD_HANDLE(CurveCreator_AISCurve, AIS_Shape)
 class CurveCreator_AISCurve : public AIS_Shape
 {
 public:
-  Standard_EXPORT CurveCreator_AISCurve( CurveCreator_ICurve* theCurve );
+  Standard_EXPORT CurveCreator_AISCurve( CurveCreator_Curve* theCurve );
 
 protected:
   /**
@@ -63,7 +64,10 @@ public:
   DEFINE_STANDARD_RTTI(CurveCreator_AISCurve)
 
 protected:
-  CurveCreator_ICurve* myCurve;
+  void getPoint( const int theSectionId, const int thePointId, gp_Pnt& thePoint );
+
+protected:
+  CurveCreator_Curve* myCurve;
 };
 
 #endif // CURVECREATOR_AIS_CURVE_H
index e359e66c44a5ee83b5259f9c46c48ac3cf57e957..0baf0775c6081b12948f5cedc59bf28f9a7275d7 100644 (file)
@@ -112,8 +112,9 @@ protected:
 
   Handle_AIS_Point getAISPoint( int theISection, int theIPoint ) const;
   Handle_AIS_Line  getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const;
+public: // temporary
   void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const;
-
+protected:  // temporary
   void redisplayCurve();
 
   void convert( const SectionToPointList &thePoints,
index 8f624b0616b7aad798a9ab2bb103ca80a930c5c6..08a78d8656d62e505d492d9245ae7bc4084a3935 100644 (file)
@@ -1056,9 +1056,15 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
     return;
 
   if ( myDragStarted ) {
-    if ( myDragged ) // if the drag of some points has happened, restore the drag selection
-      setSelectedPonts( myDragPoints );
+    bool isDragged = myDragged;
+    CurveCreator_Widget::SectionToPointList aDraggedPoints;
+    if ( myDragged )
+      aDraggedPoints = myDragPoints;
+
     setDragStarted( false );
+    // if the drag of some points has happened, restore the drag selection
+    if ( aDraggedPoints.size() > 0 )
+      setSelectedPonts( aDraggedPoints );
   }
   else // check whether the segment is clicked an a new point should be added to the segment
     insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
@@ -1289,6 +1295,8 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
 
 void CurveCreator_Widget::updateLocalPointView()
 {
+  if ( myDragStarted )
+    return;
   Handle(AIS_InteractiveContext) aContext = getAISContext();
   if ( !aContext )
     return;
@@ -1324,11 +1332,11 @@ void CurveCreator_Widget::updateLocalPointView()
           }*/
         }
       }
-      if ( aVertex.IsNull() )
-        continue;
-      aPnt = BRep_Tool::Pnt( aVertex );
-      addLocalPointToTable( aPnt.X(), aPnt.Y() );
     }
+    if ( aVertex.IsNull() )
+      continue;
+    aPnt = BRep_Tool::Pnt( aVertex );
+    addLocalPointToTable( aPnt.X(), aPnt.Y() );
   }
   myLocalPointView->blockSignals(isBlocked);
 }
@@ -1363,6 +1371,7 @@ void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool i
         {
           ic->Load( anAIS, -1/*selection mode*/, true/*allow decomposition*/ );
           ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_WIRE ) );
+          //ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) );
         }
         else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
         {
@@ -1470,6 +1479,8 @@ void CurveCreator_Widget::getSelectedPonts( CurveCreator_Widget::SectionToPointL
 
 void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionToPointList& thePoints )
 {
+  if ( myDragStarted )
+    return;
   Handle(AIS_InteractiveContext) ic = getAISContext();
   if ( !ic || !ic->HasOpenedContext() )
     return;