X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FOBJECT%2FGEOM_AssemblyBuilder.cxx;h=ebad1a415349a98c381bfc7c17fec04d4115c788;hb=5de82fb1bedaf88db38b0ee7f0d0bdd427ba39f0;hp=39aca3d9cacd25222c1a3ef6596c754717053b46;hpb=f72094caafac8a8fe54afa58ffe44879a6388258;p=modules%2Fgeom.git diff --git a/src/OBJECT/GEOM_AssemblyBuilder.cxx b/src/OBJECT/GEOM_AssemblyBuilder.cxx index 39aca3d9c..ebad1a415 100644 --- a/src/OBJECT/GEOM_AssemblyBuilder.cxx +++ b/src/OBJECT/GEOM_AssemblyBuilder.cxx @@ -1,32 +1,31 @@ -// GEOM OBJECT : interactive object for Geometry entities visualization +// Copyright (C) 2007-2010 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) 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 +// + +// GEOM OBJECT : interactive object for Geometry entities visualization // File : GEOM_AssemblyBuilder.cxx // Author : Christophe ATTANASIO // Module : GEOM // $Header$ - -using namespace std; +// /*! \class GEOM_AssemblyBuilder GEOM_AssemblyBuilder.h \brief .... @@ -34,42 +33,41 @@ using namespace std; #include "GEOM_AssemblyBuilder.h" #include "GEOM_Actor.h" -#include "utilities.h" + +#include + +#include +#include + +#include +#include +#include // Open CASCADE Includes #include -#include -#include -#include -#include #include #include #include -#include #include -// SALOME - -#define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) ) -#define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) ) - - - +// Qt includes +#include +#include "utilities.h" void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, - vtkProperty* FaceProp, - vtkProperty* EdgeFProp, - vtkProperty* EdgeSProp, - vtkProperty* EdgeIProp, - vtkProperty* VertexProp, - vtkProperty* IsoPVProp, - vtkProperty* EdgePVProp, - vtkProperty* VertexPVProp) + vtkProperty* FaceProp, + vtkProperty* EdgeFProp, + vtkProperty* EdgeSProp, + vtkProperty* EdgeIProp, + vtkProperty* VertexProp, + vtkProperty* IsoPVProp, + vtkProperty* EdgePVProp, + vtkProperty* VertexPVProp) { // Shading like default OCC material FaceProp->SetRepresentationToSurface(); - FaceProp->SetInterpolation(1); + FaceProp->SetInterpolationToGouraud(); FaceProp->SetAmbient(1.0); FaceProp->SetDiffuse(1.0); FaceProp->SetSpecular(0.4); @@ -77,12 +75,19 @@ void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, FaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725); FaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QColor aColor; + // Wireframe for iso + aColor = aResMgr->colorValue( "Geometry", "isos_color", QColor( int(0.5*255), int(0.5*255), int(0.5*255) ) ); + float red = aColor.red()/255.0; + float green = aColor.green()/255.0; + float blue = aColor.blue()/255.0; IsoProp->SetRepresentationToWireframe(); - IsoProp->SetAmbientColor(0.5, 0.5, 0.5); - IsoProp->SetDiffuseColor(0.5, 0.5, 0.5); - IsoProp->SetSpecularColor(0.5, 0.5, 0.5); - + IsoProp->SetAmbientColor(red, green, blue); + IsoProp->SetDiffuseColor(red, green, blue); + IsoProp->SetSpecularColor(red, green, blue); + // Wireframe for iso IsoPVProp->SetRepresentationToWireframe(); IsoPVProp->SetAmbientColor(0, 1, 1); @@ -90,35 +95,50 @@ void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, IsoPVProp->SetSpecularColor(0, 1, 1); // Wireframe for shared edge + aColor = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) ); + red = aColor.red()/255.0; + green = aColor.green()/255.0; + blue = aColor.blue()/255.0; EdgeSProp->SetRepresentationToWireframe(); - EdgeSProp->SetAmbientColor(1, 1, 0); - EdgeSProp->SetDiffuseColor(1, 1, 0); - EdgeSProp->SetSpecularColor(1, 1, 0); - + EdgeSProp->SetAmbientColor(red, green, blue); + EdgeSProp->SetDiffuseColor(red, green, blue); + EdgeSProp->SetSpecularColor(red, green, blue); + // Wireframe for free edge + aColor = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) ); + red = aColor.red()/255.0; + green = aColor.green()/255.0; + blue = aColor.blue()/255.0; EdgeFProp->SetRepresentationToWireframe(); - EdgeFProp->SetAmbientColor(0, 1, 0); - EdgeFProp->SetDiffuseColor(0, 1, 0); - EdgeFProp->SetSpecularColor(0, 1, 0); + EdgeFProp->SetAmbientColor(red, green, blue); + EdgeFProp->SetDiffuseColor(red, green, blue); + EdgeFProp->SetSpecularColor(red, green, blue); // Wireframe for isolated edge + aColor = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) ); + red = aColor.red()/255.0; + green = aColor.green()/255.0; + blue = aColor.blue()/255.0; EdgeIProp->SetRepresentationToWireframe(); - EdgeIProp->SetAmbientColor(1, 0, 0); - EdgeIProp->SetDiffuseColor(1, 0, 0); - EdgeIProp->SetSpecularColor(1, 0, 0); - + EdgeIProp->SetAmbientColor(red, green, blue); + EdgeIProp->SetDiffuseColor(red, green, blue); + // Wireframe for Preview edge EdgePVProp->SetRepresentationToWireframe(); - EdgePVProp->SetAmbientColor(0, 1, 1); - EdgePVProp->SetDiffuseColor(0, 1, 1); - EdgePVProp->SetSpecularColor(0, 1, 1); + EdgePVProp->SetAmbientColor(1, 1, 0); + EdgePVProp->SetDiffuseColor(1, 1, 0); + EdgePVProp->SetSpecularColor(1, 1, 0); // Wireframe for vertex + aColor = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ); + red = aColor.red()/255.0; + green = aColor.green()/255.0; + blue = aColor.blue()/255.0; VertexProp->SetRepresentationToWireframe(); - VertexProp->SetAmbientColor(1, 1, 0); - VertexProp->SetDiffuseColor(1, 1, 0); - VertexProp->SetSpecularColor(1, 1, 0); - + VertexProp->SetAmbientColor(red, green, blue); + VertexProp->SetDiffuseColor(red, green, blue); + VertexProp->SetSpecularColor(red, green, blue); + // Wireframe for vertex VertexPVProp->SetRepresentationToWireframe(); VertexPVProp->SetAmbientColor(0, 1, 1); @@ -127,52 +147,44 @@ void GEOM_AssemblyBuilder::InitProperties(vtkProperty* IsoProp, } -void GEOM_AssemblyBuilder::MeshShape(const TopoDS_Shape myShape, - Standard_Real deflection, - Standard_Boolean forced) -{ - // Mesh the shape if necessary - Standard_Boolean alreadymesh = Standard_True; - TopExp_Explorer ex; - TopLoc_Location aLoc; - - for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) { - const TopoDS_Face& aFace = TopoDS::Face(ex.Current()); - Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc); - if(aPoly.IsNull()) { alreadymesh = Standard_False; break; } - } - - if(!alreadymesh || forced) { - if(deflection<=0) { - // Compute default deflection - Bnd_Box B; - BRepBndLib::Add(myShape, B); - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - deflection = MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.001 *4; - } - BRepMesh_IncrementalMesh MESH(myShape,deflection); - } -} - - - 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) +{ + /* + vtkProperty* IsoProp = vtkProperty::New(); + vtkProperty* FaceProp = vtkProperty::New(); + vtkProperty* EdgeFProp = vtkProperty::New(); + vtkProperty* EdgeSProp = vtkProperty::New(); + vtkProperty* EdgeIProp = vtkProperty::New(); + vtkProperty* VertexProp = vtkProperty::New(); + vtkProperty* IsoPVProp = vtkProperty::New(); + vtkProperty* EdgePVProp = vtkProperty::New(); + vtkProperty* VertexPVProp = vtkProperty::New(); + InitProperties(IsoProp,FaceProp,EdgeFProp,EdgeSProp,EdgeIProp,VertexProp,IsoPVProp,EdgePVProp,VertexPVProp); + */ vtkActorCollection* AISActors = vtkActorCollection::New(); + GEOM::MeshShape(myShape,deflection,forced); + GEOM_Actor* aGeomActor = GEOM_Actor::New(); + aGeomActor->SetShape(myShape,(float)deflection,false,isVector); + AISActors->AddItem(aGeomActor); + aGeomActor->Delete(); + + /* 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(); } } } @@ -216,52 +228,54 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap TopExp_Explorer ex2; for (ex2.Init(ex.Current(), TopAbs_EDGE); ex2.More(); ex2.Next()) { - const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current()); - - if (BRep_Tool::Degenerated(aEdge)) { - continue; - } - - // compute the number of faces - Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent(); - GEOM_Actor* EdgeActor = GEOM_Actor::New(); - EdgeActor->SubShapeOn(); - EdgeActor->setInputShape(ex2.Current(),deflection,mode); - switch (nbf) { - - case 0 : // isolated edge - { - EdgeActor->SetShadingProperty(EdgeIProp); - EdgeActor->SetWireframeProperty(EdgeIProp); - } - break; - - case 1 :// edge in only one face - { - EdgeActor->SetShadingProperty(EdgeFProp); - EdgeActor->SetWireframeProperty(EdgeFProp); - } - break; - - default : // edge shared by at least two faces - { - EdgeActor->SetShadingProperty(EdgeSProp); - EdgeActor->SetWireframeProperty(EdgeSProp); - } - } - EdgeActor->SetPreviewProperty(EdgePVProp); - AISActors->AddItem(EdgeActor); + const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current()); + + if (BRep_Tool::Degenerated(aEdge)) { + continue; + } + + // compute the number of faces + Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent(); + GEOM_Actor* EdgeActor = GEOM_Actor::New(); + EdgeActor->SubShapeOn(); + EdgeActor->setInputShape(ex2.Current(),deflection,mode); + + switch (nbf) { + + case 0 : // isolated edge + { + EdgeActor->SetShadingProperty(EdgeIProp); + EdgeActor->SetWireframeProperty(EdgeIProp); + } + break; + + case 1 :// edge in only one face + { + EdgeActor->SetShadingProperty(EdgeFProp); + EdgeActor->SetWireframeProperty(EdgeFProp); + } + break; + + default : // edge shared by at least two faces + { + EdgeActor->SetShadingProperty(EdgeSProp); + EdgeActor->SetWireframeProperty(EdgeSProp); + } + } + + EdgeActor->SetPreviewProperty(EdgePVProp); + AISActors->AddItem(EdgeActor); } } } else if ( myShape.ShapeType() == TopAbs_WIRE ) { // WIRE Actor TopExp_Explorer ex; for (ex.Init(myShape, TopAbs_EDGE); ex.More(); ex.Next()) { const TopoDS_Edge& aEdge = TopoDS::Edge(ex.Current()); - + if (BRep_Tool::Degenerated(aEdge)) { - continue; + continue; } - + GEOM_Actor* EdgeActor = GEOM_Actor::New(); EdgeActor->setInputShape(ex.Current(),deflection,mode); EdgeActor->SetShadingProperty(EdgeIProp); @@ -272,7 +286,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); @@ -288,6 +302,8 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap AISActors->AddItem(VertexActor); } + */ + return AISActors; @@ -299,15 +315,14 @@ vtkActorCollection* GEOM_AssemblyBuilder::BuildActors(const TopoDS_Shape& myShap // BUILD ASSEMBLY //------------------------------------------------------------- vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape, - Standard_Real deflection, - Standard_Integer mode, - Standard_Boolean forced) + Standard_Real deflection, + Standard_Integer mode, + Standard_Boolean forced) { // Create a new vtkAssembly vtkAssembly* myVTKShape = vtkAssembly::New(); - - + /* // Create graphics properties vtkProperty* IsoProp = vtkProperty::New(); @@ -351,7 +366,7 @@ vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape, const TopoDS_Edge& aEdge = TopoDS::Edge(ex2.Current()); if (BRep_Tool::Degenerated(aEdge)) { - continue; + continue; } @@ -359,26 +374,26 @@ vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape, Standard_Integer nbf = edgemap.FindFromKey(ex2.Current()).Extent(); GEOM_Actor* EdgeActor = GEOM_Actor::New(); switch (nbf) { - + case 0 : // isolated edge - { - EdgeActor->SetShadingProperty(EdgeIProp); - EdgeActor->SetWireframeProperty(EdgeIProp); - } - break; - + { + EdgeActor->SetShadingProperty(EdgeIProp); + EdgeActor->SetWireframeProperty(EdgeIProp); + } + break; + case 1 :// edge in only one face - { - EdgeActor->SetShadingProperty(EdgeFProp); - EdgeActor->SetWireframeProperty(EdgeFProp); - } - break; - + { + EdgeActor->SetShadingProperty(EdgeFProp); + EdgeActor->SetWireframeProperty(EdgeFProp); + } + break; + default : // edge shared by at least two faces - { - EdgeActor->SetShadingProperty(EdgeSProp); - EdgeActor->SetWireframeProperty(EdgeSProp); - } + { + EdgeActor->SetShadingProperty(EdgeSProp); + EdgeActor->SetWireframeProperty(EdgeSProp); + } } EdgeActor->setInputShape(ex2.Current(),deflection,mode); @@ -386,6 +401,8 @@ vtkAssembly* GEOM_AssemblyBuilder::BuildAssembly(const TopoDS_Shape& myShape, } myVTKShape->AddPart(myFaceAssembly); } + + */ return myVTKShape;