PAL12874: Object Vector. Provide a possibility to display a vector with arrow on its end.

This commit is contained in:
jfa 2007-02-19 11:53:20 +00:00
parent 94292c2770
commit 916e6ce885
11 changed files with 288 additions and 46 deletions

View File

@ -115,11 +115,9 @@ static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
} }
GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape, 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 ); myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
} }
@ -140,8 +138,7 @@ Standard_Boolean GEOM_AISShape::hasIO(){
void GEOM_AISShape::setName(const Standard_CString aName) void GEOM_AISShape::setName(const Standard_CString aName)
{ {
myName = new char [strlen(aName)+1]; myName = aName;
strcpy( myName, aName);
Handle(SALOME_InteractiveObject) IO = getIO(); Handle(SALOME_InteractiveObject) IO = getIO();
if ( !IO.IsNull() ) if ( !IO.IsNull() )
@ -149,7 +146,7 @@ void GEOM_AISShape::setName(const Standard_CString aName)
} }
Standard_CString GEOM_AISShape::getName(){ Standard_CString GEOM_AISShape::getName(){
return myName; return myName.ToCString();
} }
void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,

View File

@ -53,6 +53,8 @@
#include <Handle_Prs3d_Presentation.hxx> #include <Handle_Prs3d_Presentation.hxx>
#endif #endif
#include <TCollection_AsciiString.hxx>
class PrsMgr_PresentationManager3d; class PrsMgr_PresentationManager3d;
class Prs3d_Presentation; class Prs3d_Presentation;
class SALOME_InteractiveObject; class SALOME_InteractiveObject;
@ -105,34 +107,16 @@ public:
// //
friend Handle_Standard_Type& GEOM_AISShape_Type_(); friend Handle_Standard_Type& GEOM_AISShape_Type_();
const Handle(Standard_Type)& DynamicType() const; const Handle(Standard_Type)& DynamicType() const;
Standard_Boolean IsKind(const Handle(Standard_Type)&) const; Standard_Boolean IsKind(const Handle(Standard_Type)&) const;
protected:
// Methods PROTECTED
//
// Fields PROTECTED
//
protected:
Quantity_Color myShadingColor;
private: private:
TCollection_AsciiString myName;
// Methods PRIVATE
//
// Fields PRIVATE
//
Standard_CString myName;
Quantity_Color myShadingColor;
}; };
// other inline functions and methods (like "C++: function call" methods) // other inline functions and methods (like "C++: function call" methods)
// //

View File

@ -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...
}

View File

@ -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

View File

@ -113,7 +113,7 @@ void GEOM_Actor::ShallowCopy(vtkProp *prop)
GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop); GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
if ( f != NULL ) 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() ); this->setName( f->getName() );
if ( f->hasIO() ) if ( f->hasIO() )
this->setIO( f->getIO() ); this->setIO( f->getIO() );
@ -155,9 +155,12 @@ void GEOM_Actor::setDeflection(double adef) {
deflection = 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; myShape = aShape;
deflection = adef; deflection = adef;
myIsVector = isVector;
setDisplayMode(imode); setDisplayMode(imode);
} }
@ -192,10 +195,10 @@ void GEOM_Actor::CreateMapper(int theMode) {
this->SetPosition(aPnt.X(),aPnt.Y(),aPnt.Z()); this->SetPosition(aPnt.X(),aPnt.Y(),aPnt.Z());
} }
GEOM_OCCReader* aread = GEOM_OCCReader::New(); GEOM_OCCReader* aread = GEOM_OCCReader::New();
aread->setTopo(myShape); aread->setTopo(myShape, myIsVector);
aread->setDisplayMode(theMode); aread->setDisplayMode(theMode);
aread->GetOutput()->ReleaseDataFlagOn(); aread->GetOutput()->ReleaseDataFlagOn();
vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
if (theMode == 0) { if (theMode == 0) {
aMapper->SetInput(aread->GetOutput()); aMapper->SetInput(aread->GetOutput());

View File

@ -62,11 +62,14 @@ class SALOME_WNT_EXPORT GEOM_Actor : public SALOME_Actor {
void ReleaseGraphicsResources(vtkWindow *); void ReleaseGraphicsResources(vtkWindow *);
const TopoDS_Shape& getTopo(); 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(); double getDeflection();
void setDeflection(double adefl); void setDeflection(double adefl);
double isVector() { return myIsVector; }
// SubShape // SubShape
void SubShapeOn(); void SubShapeOn();
void SubShapeOff(); void SubShapeOff();
@ -114,6 +117,7 @@ class SALOME_WNT_EXPORT GEOM_Actor : public SALOME_Actor {
TopoDS_Shape myShape; TopoDS_Shape myShape;
double deflection; double deflection;
bool myIsVector;
vtkMapper* ShadingMapper; vtkMapper* ShadingMapper;
vtkMapper* WireframeMapper; vtkMapper* WireframeMapper;

View File

@ -185,21 +185,23 @@ void GEOM_AssemblyBuilder::MeshShape(const TopoDS_Shape myShape,
vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShape, vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShape,
Standard_Real deflection, Standard_Real deflection,
Standard_Integer mode, Standard_Integer mode,
Standard_Boolean forced) { Standard_Boolean forced,
Standard_Boolean isVector)
{
vtkActorCollection* AISActors = vtkActorCollection::New(); vtkActorCollection* AISActors = vtkActorCollection::New();
if(myShape.ShapeType() == TopAbs_COMPOUND) { if(myShape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator anItr(myShape); TopoDS_Iterator anItr(myShape);
for(; anItr.More(); anItr.Next()) { 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(); theActors->InitTraversal();
vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
while(!(anActor==NULL)) { while(!(anActor==NULL)) {
AISActors->AddItem(anActor); AISActors->AddItem(anActor);
anActor = (vtkActor*)theActors->GetNextActor(); anActor = (vtkActor*)theActors->GetNextActor();
} }
} }
} }
@ -301,7 +303,7 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap
} }
} else if ( myShape.ShapeType() == TopAbs_EDGE ) { // EDGE Actor } else if ( myShape.ShapeType() == TopAbs_EDGE ) { // EDGE Actor
GEOM_Actor* EdgeActor = GEOM_Actor::New(); GEOM_Actor* EdgeActor = GEOM_Actor::New();
EdgeActor->setInputShape(myShape,deflection,mode); EdgeActor->setInputShape(myShape,deflection,mode,isVector);
EdgeActor->SetShadingProperty(EdgeIProp); EdgeActor->SetShadingProperty(EdgeIProp);
EdgeActor->SetWireframeProperty(EdgeIProp); EdgeActor->SetWireframeProperty(EdgeIProp);
EdgeActor->SetPreviewProperty(EdgePVProp); EdgeActor->SetPreviewProperty(EdgePVProp);

View File

@ -78,7 +78,8 @@ class SALOME_WNT_EXPORT GEOM_AssemblyBuilder {
static vtkActorCollection* BuildActors(const TopoDS_Shape& myShape, static vtkActorCollection* BuildActors(const TopoDS_Shape& myShape,
Standard_Real deflection, Standard_Real deflection,
Standard_Integer amode, Standard_Integer amode,
Standard_Boolean forced); Standard_Boolean forced,
Standard_Boolean isVector = Standard_False);
//------------------------------------------------------------------ //------------------------------------------------------------------

View File

@ -740,14 +740,19 @@ void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
edgeTransf = aEdgeLoc.Transformation(); edgeTransf = aEdgeLoc.Transformation();
} }
gp_Pnt aP1, aP2;
Standard_Integer nbnodes; Standard_Integer nbnodes;
if (aEdgePoly.IsNull()) { if (aEdgePoly.IsNull()) {
nbnodes = P->NbNodes(); nbnodes = P->NbNodes();
const TColgp_Array1OfPnt& theNodesP = P->Nodes(); const TColgp_Array1OfPnt& theNodesP = P->Nodes();
aP1 = theNodesP(1);
aP2 = theNodesP(nbnodes);
float coord[3]; float coord[3];
int pts[2]; int pts[2];
for(int j=1;j<nbnodes;j++) { for(int j=1;j<nbnodes;j++) {
gp_Pnt pt1 = theNodesP(j); gp_Pnt pt1 = theNodesP(j);
gp_Pnt pt2 = theNodesP(j+1); 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 TColStd_Array1OfInteger& Nodesidx = aEdgePoly->Nodes();
const TColgp_Array1OfPnt& theNodesPoly = T->Nodes(); const TColgp_Array1OfPnt& theNodesPoly = T->Nodes();
aP1 = theNodesPoly(1);
aP2 = theNodesPoly(nbnodes);
float coord[3]; float coord[3];
int pts[2]; int pts[2];
@ -802,6 +810,91 @@ void GEOM_OCCReader::TransferEdgeWData(const TopoDS_Edge& aEdge,
Cells->InsertNextCell(2,pts); 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(); /* Standard_Integer nbnodes = aEdgePoly->NbNodes();
@ -972,8 +1065,9 @@ void GEOM_OCCReader::setDisplayMode(int thenewmode) {
amode = thenewmode; amode = thenewmode;
} }
void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape) { void GEOM_OCCReader::setTopo(const TopoDS_Shape& aShape, bool isVector) {
myShape = aShape; myShape = aShape;
myIsVector = isVector;
} }
void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) { void GEOM_OCCReader::setForceUpdate(Standard_Boolean bol) {

View File

@ -63,7 +63,7 @@ class VTKOCC_EXPORT GEOM_OCCReader : public vtkPolyDataSource {
const TopoDS_Shape& getTopo(); const TopoDS_Shape& getTopo();
void setTopo(const TopoDS_Shape& ashape); void setTopo(const TopoDS_Shape& ashape, bool isVector = false);
int getDisplayMode(); int getDisplayMode();
void setDisplayMode(int); void setDisplayMode(int);
@ -137,6 +137,7 @@ class VTKOCC_EXPORT GEOM_OCCReader : public vtkPolyDataSource {
int amode; int amode;
int nbisos; int nbisos;
TopoDS_Shape myShape; TopoDS_Shape myShape;
bool myIsVector;
}; };

View File

@ -36,6 +36,7 @@ EXPORT_HEADERS = GEOM_Actor.h \
GEOM_AssemblyBuilder.h \ GEOM_AssemblyBuilder.h \
GEOM_AISShape.hxx \ GEOM_AISShape.hxx \
Handle_GEOM_AISShape.hxx \ Handle_GEOM_AISShape.hxx \
GEOM_AISVector.hxx \
GEOM_InteractiveObject.hxx \ GEOM_InteractiveObject.hxx \
Handle_GEOM_InteractiveObject.hxx \ Handle_GEOM_InteractiveObject.hxx \
GEOM_AISTrihedron.hxx \ GEOM_AISTrihedron.hxx \
@ -48,6 +49,7 @@ LIB_SRC = GEOM_Actor.cxx \
GEOM_OCCReader.cxx \ GEOM_OCCReader.cxx \
GEOM_AssemblyBuilder.cxx \ GEOM_AssemblyBuilder.cxx \
GEOM_AISShape.cxx \ GEOM_AISShape.cxx \
GEOM_AISVector.cxx \
GEOM_InteractiveObject.cxx \ GEOM_InteractiveObject.cxx \
GEOM_AISTrihedron.cxx \ GEOM_AISTrihedron.cxx \
GEOM_VTKTrihedron.cxx GEOM_VTKTrihedron.cxx