]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
PAL12874: Object Vector. Provide a possibility to display a vector with arrow on...
authorjfa <jfa@opencascade.com>
Mon, 19 Feb 2007 11:53:20 +0000 (11:53 +0000)
committerjfa <jfa@opencascade.com>
Mon, 19 Feb 2007 11:53:20 +0000 (11:53 +0000)
src/OBJECT/GEOM_AISShape.cxx
src/OBJECT/GEOM_AISShape.hxx
src/OBJECT/GEOM_AISVector.cxx [new file with mode: 0644]
src/OBJECT/GEOM_AISVector.hxx [new file with mode: 0644]
src/OBJECT/GEOM_Actor.cxx
src/OBJECT/GEOM_Actor.h
src/OBJECT/GEOM_AssemblyBuilder.cxx
src/OBJECT/GEOM_AssemblyBuilder.h
src/OBJECT/GEOM_OCCReader.cxx
src/OBJECT/GEOM_OCCReader.h
src/OBJECT/Makefile.in

index 7c89cd2fe148a1a6d3b0f0ed960bb13a6b2ab6e7..0a29599c5b079b6d193959aaba4887856c225358 100644 (file)
@@ -115,11 +115,9 @@ static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
 }
 
 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
-                            const Standard_CString aName): SALOME_AISShape(shape)
+                            const Standard_CString aName)
+  : SALOME_AISShape(shape), myName(aName)
 {
-  myName = new char [strlen(aName)+1];
-  strcpy( myName, aName);
-
   myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
 }
 
@@ -140,8 +138,7 @@ Standard_Boolean GEOM_AISShape::hasIO(){
 
 void GEOM_AISShape::setName(const Standard_CString aName)
 {
-  myName = new char [strlen(aName)+1];
-  strcpy( myName, aName);
+  myName = aName;
 
   Handle(SALOME_InteractiveObject) IO = getIO();
   if ( !IO.IsNull() )
@@ -149,7 +146,7 @@ void GEOM_AISShape::setName(const Standard_CString aName)
 }
 
 Standard_CString GEOM_AISShape::getName(){
-  return myName;
+  return myName.ToCString();
 }
 
 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
index 2cbf8b2b062943a4f5617a0a74b6ff78675d8f33..ff561732079437d20f510f37c3b5c36cf2575842 100644 (file)
@@ -53,6 +53,8 @@
 #include <Handle_Prs3d_Presentation.hxx>
 #endif
 
+#include <TCollection_AsciiString.hxx>
+
 class PrsMgr_PresentationManager3d;
 class Prs3d_Presentation;
 class SALOME_InteractiveObject;
@@ -105,34 +107,16 @@ public:
  //
        friend Handle_Standard_Type& GEOM_AISShape_Type_();
        const Handle(Standard_Type)& DynamicType() const;
-       Standard_Boolean              IsKind(const Handle(Standard_Type)&) const;
-
-protected:
-
- // Methods PROTECTED
- // 
-
-
- // Fields PROTECTED
- //
+       Standard_Boolean             IsKind(const Handle(Standard_Type)&) const;
 
+protected: 
+  Quantity_Color myShadingColor;
 
 private: 
-
- // Methods PRIVATE
- // 
-
-
- // Fields PRIVATE
- //
-  Standard_CString myName;
-  Quantity_Color myShadingColor;
+  TCollection_AsciiString myName;
 };
 
 
-
-
-
 // other inline functions and methods (like "C++: function call" methods)
 //
 
diff --git a/src/OBJECT/GEOM_AISVector.cxx b/src/OBJECT/GEOM_AISVector.cxx
new file mode 100644 (file)
index 0000000..7c4da87
--- /dev/null
@@ -0,0 +1,91 @@
+// GEOM OBJECT : interactive object for Geometry entities visualization
+//
+// Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File   : GEOM_AISVector.cxx
+// Author : Julia DOROVSKIKH
+// $Header$
+
+
+#include <GEOM_AISVector.hxx>
+
+// OCCT Includes
+#include <Prs3d_Presentation.hxx>
+#include <Prs3d_Arrow.hxx>
+#include <PrsMgr_PresentationManager3d.hxx>
+#include <Graphic3d_Group.hxx>
+#include <BRep_Tool.hxx>
+#include <TopExp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Dir.hxx>
+#include <gp_Vec.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(GEOM_AISVector, GEOM_AISShape)
+IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISVector, GEOM_AISShape)
+
+//=======================================================================
+//function : GEOM_AISVector
+//purpose  : Constructor
+//=======================================================================
+GEOM_AISVector::GEOM_AISVector (const TopoDS_Shape& theShape, const Standard_CString theName)
+  : GEOM_AISShape(theShape, theName)
+{
+}
+
+//=======================================================================
+//function : Compute
+//purpose  : Compute a presentation
+//=======================================================================
+void GEOM_AISVector::Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                              const Handle(Prs3d_Presentation)& thePrs,
+                              const Standard_Integer theMode)
+{
+  GEOM_AISShape::Compute(thePresentationManager, thePrs, theMode);
+
+  if (myshape.ShapeType() == TopAbs_EDGE)
+  {
+    TopoDS_Vertex aV1, aV2;
+    TopoDS_Edge anEdgeE = TopoDS::Edge(myshape);
+    TopExp::Vertices(anEdgeE, aV1, aV2);
+    gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
+    gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
+
+    gp_Vec aVec (aP1, aP2);
+    Standard_Real aDist = aVec.Magnitude();
+    if (aDist > gp::Resolution())
+    {
+      gp_Dir aDir (aVec);
+
+      Handle(Graphic3d_Group) aG = Prs3d_Root::CurrentGroup(thePrs);
+
+      thePrs->Color(myShadingColor.Name());
+      //aG->BeginPrimitives();
+      Prs3d_Arrow::Draw(thePrs, aP2, aDir, PI/180.*5., aDist/10.);
+      //aG->EndPrimitives();
+    }
+  }
+  //thePrs->ReCompute(); // for hidden line recomputation if necessary...
+}
diff --git a/src/OBJECT/GEOM_AISVector.hxx b/src/OBJECT/GEOM_AISVector.hxx
new file mode 100644 (file)
index 0000000..993e17c
--- /dev/null
@@ -0,0 +1,63 @@
+// GEOM OBJECT : interactive object for Geometry entities visualization
+//
+// Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+// File   : GEOM_AISVector.hxx
+// Author : Julia DOROVSKIKH
+// Module : GEOM
+
+#ifndef GEOM_AISVector_HeaderFile
+#define GEOM_AISVector_HeaderFile
+
+#include <GEOM_AISShape.hxx>
+#include <Standard_DefineHandle.hxx>
+
+/*!
+ * \class GEOM_AISVector
+ * \brief Interactive object, representing a vector with arrow on its end
+ */
+
+class GEOM_AISVector : public GEOM_AISShape
+{
+public:
+  /*!
+   * Constructor
+   * \param theShape A linear edge to be represented as a vector
+   * \param theName A name to be passed in constructor of \a GEOM_AISShape
+   */
+  Standard_EXPORT GEOM_AISVector (const TopoDS_Shape& theShape, const Standard_CString theName);
+
+protected:
+  /*!
+   * Redefined from GEOM_AISShape
+   */
+  virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                        const Handle(Prs3d_Presentation)& thePresentation,
+                        const Standard_Integer theMode = 0);
+
+public:
+  DEFINE_STANDARD_RTTI (GEOM_AISVector)
+};
+
+DEFINE_STANDARD_HANDLE(GEOM_AISVector, GEOM_AISShape)
+
+#endif
index 0e7f3ccbaf1b1f25aa34529dc850d2454426a56b..e1ff415418bc65d33122661f1d44c6921443ed0b 100644 (file)
@@ -113,7 +113,7 @@ void GEOM_Actor::ShallowCopy(vtkProp *prop)
   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
   if ( f != NULL )
     {
-      this->setInputShape(f->getTopo(),f->getDeflection(),f->getDisplayMode());
+      this->setInputShape(f->getTopo(),f->getDeflection(),f->getDisplayMode(),f->isVector());
       this->setName( f->getName() );
       if ( f->hasIO() )
        this->setIO( f->getIO() );
@@ -155,9 +155,12 @@ void GEOM_Actor::setDeflection(double adef) {
   deflection = adef;
 }
 
-void GEOM_Actor::setInputShape(const TopoDS_Shape& aShape,double adef,int imode) {
+void GEOM_Actor::setInputShape(const TopoDS_Shape& aShape, double adef,
+                               int imode, bool isVector)
+{
   myShape = aShape;
   deflection = adef;
+  myIsVector = isVector;
   setDisplayMode(imode);
 }
 
@@ -192,10 +195,10 @@ void GEOM_Actor::CreateMapper(int theMode) {
     this->SetPosition(aPnt.X(),aPnt.Y(),aPnt.Z());
   }
   GEOM_OCCReader* aread = GEOM_OCCReader::New();
-  aread->setTopo(myShape);
+  aread->setTopo(myShape, myIsVector);
   aread->setDisplayMode(theMode);
   aread->GetOutput()->ReleaseDataFlagOn(); 
-    
+
   vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
   if (theMode == 0) { 
     aMapper->SetInput(aread->GetOutput());
index f2236aea1f763e1af9ceac7e8f9d0de0f815da73..25c713d1090979c3aeebad034ee252be90b1a6fd 100644 (file)
@@ -62,11 +62,14 @@ class SALOME_WNT_EXPORT GEOM_Actor : public SALOME_Actor {
   void ReleaseGraphicsResources(vtkWindow *);
 
   const TopoDS_Shape& getTopo();
-  void setInputShape(const TopoDS_Shape& ashape,double adef1,int imode);
+  void setInputShape(const TopoDS_Shape& ashape, double adef1,
+                    int imode, bool isVector = false);
 
   double getDeflection();
   void setDeflection(double adefl);
 
+  double isVector() { return myIsVector; }
+
   // SubShape
   void SubShapeOn();
   void SubShapeOff();
@@ -114,6 +117,7 @@ class SALOME_WNT_EXPORT GEOM_Actor : public SALOME_Actor {
 
   TopoDS_Shape myShape;
   double deflection;
+  bool myIsVector;
 
   vtkMapper* ShadingMapper;
   vtkMapper* WireframeMapper;
index b4d94c841d0f1a62d5522d6c98a1388099b3c2ff..cb1a8ba03cd8e09df2f6aadf63ac50fa1a1e6991 100644 (file)
@@ -185,21 +185,23 @@ void GEOM_AssemblyBuilder::MeshShape(const TopoDS_Shape myShape,
 
 
 vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShape,
-                                                         Standard_Real deflection,
-                                                         Standard_Integer mode,
-                                                         Standard_Boolean forced) {
-
+                                                      Standard_Real    deflection,
+                                                      Standard_Integer mode,
+                                                      Standard_Boolean forced,
+                                                      Standard_Boolean isVector)
+{
   vtkActorCollection* AISActors = vtkActorCollection::New();
 
   if(myShape.ShapeType() == TopAbs_COMPOUND) {
     TopoDS_Iterator anItr(myShape);
     for(; anItr.More(); anItr.Next()) {
-      vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(anItr.Value(), deflection, mode, forced);
+      vtkActorCollection* theActors =
+        GEOM_AssemblyBuilder::BuildActors(anItr.Value(), deflection, mode, forced);
       theActors->InitTraversal();
       vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
       while(!(anActor==NULL)) {
-       AISActors->AddItem(anActor);
-       anActor = (vtkActor*)theActors->GetNextActor();
+        AISActors->AddItem(anActor);
+        anActor = (vtkActor*)theActors->GetNextActor();
       }
     }
   }
@@ -301,7 +303,7 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap
     }
   } else if ( myShape.ShapeType() == TopAbs_EDGE ) { // EDGE Actor
     GEOM_Actor* EdgeActor = GEOM_Actor::New();
-    EdgeActor->setInputShape(myShape,deflection,mode);
+    EdgeActor->setInputShape(myShape,deflection,mode,isVector);
     EdgeActor->SetShadingProperty(EdgeIProp);
     EdgeActor->SetWireframeProperty(EdgeIProp);
     EdgeActor->SetPreviewProperty(EdgePVProp);
index 2fd7014bdbe80211652156beca26bb3b5224a342..1d370d08711c8dc7e36296856fc5b84dbb759fe1 100644 (file)
@@ -78,7 +78,8 @@ class SALOME_WNT_EXPORT GEOM_AssemblyBuilder {
   static vtkActorCollection* BuildActors(const TopoDS_Shape& myShape,
                                         Standard_Real deflection,
                                         Standard_Integer amode,
-                                        Standard_Boolean forced);
+                                        Standard_Boolean forced,
+                                        Standard_Boolean isVector = Standard_False);
 
 
   //------------------------------------------------------------------
index 2bd8dad5d08572c3bfd56ef81b40bbaf20e88999..01400b67f43bca1890e1b3084fc0a39d7ddf9df5 100644 (file)
@@ -740,14 +740,19 @@ void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
     edgeTransf = aEdgeLoc.Transformation();
   }
 
+  gp_Pnt aP1, aP2;
+
   Standard_Integer nbnodes;
   if (aEdgePoly.IsNull()) {
     nbnodes = P->NbNodes();
     const TColgp_Array1OfPnt& theNodesP = P->Nodes();
 
+    aP1 = theNodesP(1);
+    aP2 = theNodesP(nbnodes);
+
     float coord[3];
     int pts[2];
-  
+
     for(int j=1;j<nbnodes;j++) {
       gp_Pnt pt1 = theNodesP(j);
       gp_Pnt pt2 = theNodesP(j+1);
@@ -774,6 +779,9 @@ void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
     const TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
     const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
 
+    aP1 = theNodesPoly(1);
+    aP2 = theNodesPoly(nbnodes);
+
     float coord[3];
     int pts[2];
     
@@ -802,6 +810,91 @@ void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
       Cells->InsertNextCell(2,pts);
     }
   }
+
+  // vector representation has an arrow on its end
+  if (myIsVector)
+  {
+    if (!isidtrsf) {
+      // apply edge transformation
+      aP1.Transform(edgeTransf);
+      aP2.Transform(edgeTransf);
+    }
+
+    // draw an arrow
+    gp_Vec aDirVec (aP1, aP2);
+    Standard_Real aDist = aDirVec.Magnitude();
+    if (aDist < gp::Resolution()) return;
+    gp_Dir aDirection (aDirVec);
+
+    Standard_Real anAngle = PI/180.*5.;
+    Standard_Real aLength = aDist/10.;
+
+    Standard_Real dx,dy,dz;
+    aDirection.Coord(dx,dy,dz);
+
+    // Pointe de la fleche
+    Standard_Real xo,yo,zo;
+    aP2.Coord(xo,yo,zo);
+
+    // Centre du cercle base de la fleche
+    gp_XYZ aPc = aP2.XYZ() - aDirection.XYZ() * aLength;
+
+    // Construction d'un repere i,j pour le cercle
+    gp_Dir aDirN;
+    if      (Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) aDirN = gp::DX();
+    else if (Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) aDirN = gp::DY();
+    else aDirN = gp::DZ();
+
+    gp_Dir aDirI = aDirection ^ aDirN;
+    gp_Dir aDirJ = aDirection ^ aDirI;
+
+    // Add points and segments, composing the arrow
+    Standard_Real cosinus, sinus, Tg = tan(anAngle);
+
+    float coord[3];
+    coord[0] = xo; coord[1] = yo; coord[2] = zo;
+
+    int ptLoc = Pts->InsertNextPoint(coord);
+    int ptFirst = 0;
+    int ptPrev = 0;
+    int ptCur = 0;
+
+    int pts[2];
+
+    int NbPoints = 15;
+    for (int i = 1; i <= NbPoints; i++, ptPrev = ptCur)
+    {
+      cosinus = cos(2. * PI / NbPoints * (i-1));   
+      sinus   = sin(2. * PI / NbPoints * (i-1));
+
+      gp_XYZ aP = aPc + (aDirI.XYZ() * cosinus + aDirJ.XYZ() * sinus) * aLength * Tg;
+      coord[0] = aP.X();
+      coord[1] = aP.Y();
+      coord[2] = aP.Z();
+
+      // insert pts
+      ptCur = Pts->InsertNextPoint(coord);
+      pts[0] = ptCur;
+
+      if (i == 1) {
+        ptFirst = ptCur;
+      }
+      else {
+        // insert line (ptCur,ptPrev)
+        pts[1] = ptPrev;
+        Cells->InsertNextCell(2,pts);
+      }
+
+      // insert line (ptCur,ptLoc)
+      pts[1] = ptLoc;
+      Cells->InsertNextCell(2,pts);
+    }
+
+    // insert line (ptCur,ptFirst)
+    pts[0] = ptCur;
+    pts[1] = ptFirst;
+    Cells->InsertNextCell(2,pts);
+  }
 }
 
 /*  Standard_Integer nbnodes = aEdgePoly->NbNodes();
@@ -972,8 +1065,9 @@ void GEOM_OCCReader::setDisplayMode(int thenewmode) {
   amode = thenewmode;
 }
 
-void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape) {
+void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape, bool isVector) {
   myShape = aShape;
+  myIsVector = isVector;
 }
 
 void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {
index 6592e42d4c1e995423dbbe8a1b97e70e99db297d..707b8136fe1fe9f2d6317b9e214533dbbe5d1cd3 100644 (file)
@@ -63,7 +63,7 @@ class VTKOCC_EXPORT GEOM_OCCReader : public vtkPolyDataSource {
 
   const TopoDS_Shape& getTopo();
 
-  void setTopo(const TopoDS_Shape& ashape);
+  void setTopo(const TopoDS_Shape& ashape, bool isVector = false);
 
   int  getDisplayMode();
   void setDisplayMode(int);
@@ -137,6 +137,7 @@ class VTKOCC_EXPORT GEOM_OCCReader : public vtkPolyDataSource {
   int                   amode;
   int                    nbisos;
   TopoDS_Shape           myShape;
+  bool                   myIsVector;
 
 };
 
index 0677ec36cf58f5484f6e1bc1b417f48656952a2c..55fd9578f37d21b2424c0c4cdb78cb1df4a29d0d 100644 (file)
@@ -36,6 +36,7 @@ EXPORT_HEADERS = GEOM_Actor.h \
                 GEOM_AssemblyBuilder.h \
                 GEOM_AISShape.hxx \
                 Handle_GEOM_AISShape.hxx \
+                GEOM_AISVector.hxx \
                 GEOM_InteractiveObject.hxx \
                 Handle_GEOM_InteractiveObject.hxx \
                 GEOM_AISTrihedron.hxx \
@@ -48,6 +49,7 @@ LIB_SRC =      GEOM_Actor.cxx \
                 GEOM_OCCReader.cxx \
                 GEOM_AssemblyBuilder.cxx \
                 GEOM_AISShape.cxx \
+                GEOM_AISVector.cxx \
                 GEOM_InteractiveObject.cxx \
                 GEOM_AISTrihedron.cxx \
                 GEOM_VTKTrihedron.cxx