From 916e6ce88544908a812337c1fa41e48c3bce5008 Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 19 Feb 2007 11:53:20 +0000 Subject: [PATCH] PAL12874: Object Vector. Provide a possibility to display a vector with arrow on its end. --- src/OBJECT/GEOM_AISShape.cxx | 11 ++-- src/OBJECT/GEOM_AISShape.hxx | 28 ++------- src/OBJECT/GEOM_AISVector.cxx | 91 +++++++++++++++++++++++++++ src/OBJECT/GEOM_AISVector.hxx | 63 +++++++++++++++++++ src/OBJECT/GEOM_Actor.cxx | 11 ++-- src/OBJECT/GEOM_Actor.h | 6 +- src/OBJECT/GEOM_AssemblyBuilder.cxx | 18 +++--- src/OBJECT/GEOM_AssemblyBuilder.h | 3 +- src/OBJECT/GEOM_OCCReader.cxx | 98 ++++++++++++++++++++++++++++- src/OBJECT/GEOM_OCCReader.h | 3 +- src/OBJECT/Makefile.in | 2 + 11 files changed, 288 insertions(+), 46 deletions(-) create mode 100644 src/OBJECT/GEOM_AISVector.cxx create mode 100644 src/OBJECT/GEOM_AISVector.hxx diff --git a/src/OBJECT/GEOM_AISShape.cxx b/src/OBJECT/GEOM_AISShape.cxx index 7c89cd2fe..0a29599c5 100644 --- a/src/OBJECT/GEOM_AISShape.cxx +++ b/src/OBJECT/GEOM_AISShape.cxx @@ -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, diff --git a/src/OBJECT/GEOM_AISShape.hxx b/src/OBJECT/GEOM_AISShape.hxx index 2cbf8b2b0..ff5617320 100644 --- a/src/OBJECT/GEOM_AISShape.hxx +++ b/src/OBJECT/GEOM_AISShape.hxx @@ -53,6 +53,8 @@ #include #endif +#include + 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 index 000000000..7c4da87f5 --- /dev/null +++ b/src/OBJECT/GEOM_AISVector.cxx @@ -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 + +// OCCT Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 index 000000000..993e17c33 --- /dev/null +++ b/src/OBJECT/GEOM_AISVector.hxx @@ -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 +#include + +/*! + * \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 diff --git a/src/OBJECT/GEOM_Actor.cxx b/src/OBJECT/GEOM_Actor.cxx index 0e7f3ccba..e1ff41541 100644 --- a/src/OBJECT/GEOM_Actor.cxx +++ b/src/OBJECT/GEOM_Actor.cxx @@ -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()); diff --git a/src/OBJECT/GEOM_Actor.h b/src/OBJECT/GEOM_Actor.h index f2236aea1..25c713d10 100644 --- a/src/OBJECT/GEOM_Actor.h +++ b/src/OBJECT/GEOM_Actor.h @@ -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; diff --git a/src/OBJECT/GEOM_AssemblyBuilder.cxx b/src/OBJECT/GEOM_AssemblyBuilder.cxx index b4d94c841..cb1a8ba03 100644 --- a/src/OBJECT/GEOM_AssemblyBuilder.cxx +++ b/src/OBJECT/GEOM_AssemblyBuilder.cxx @@ -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); diff --git a/src/OBJECT/GEOM_AssemblyBuilder.h b/src/OBJECT/GEOM_AssemblyBuilder.h index 2fd7014bd..1d370d087 100644 --- a/src/OBJECT/GEOM_AssemblyBuilder.h +++ b/src/OBJECT/GEOM_AssemblyBuilder.h @@ -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); //------------------------------------------------------------------ diff --git a/src/OBJECT/GEOM_OCCReader.cxx b/src/OBJECT/GEOM_OCCReader.cxx index 2bd8dad5d..01400b67f 100644 --- a/src/OBJECT/GEOM_OCCReader.cxx +++ b/src/OBJECT/GEOM_OCCReader.cxx @@ -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;jNodes(); 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) { diff --git a/src/OBJECT/GEOM_OCCReader.h b/src/OBJECT/GEOM_OCCReader.h index 6592e42d4..707b8136f 100644 --- a/src/OBJECT/GEOM_OCCReader.h +++ b/src/OBJECT/GEOM_OCCReader.h @@ -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; }; diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 0677ec36c..55fd9578f 100644 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -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 -- 2.39.2