1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH OBJECT : interactive object for SMESH visualization
21 // File : SMESH_PreviewActorsCollection.cxx
25 #include "SMESH_PreviewActorsCollection.h"
27 #include "utilities.h"
29 #include "SALOME_InteractiveObject.hxx"
34 #include <TopExp_Explorer.hxx>
37 #include <vtkUnstructuredGrid.h>
39 #include <vtkRenderer.h>
40 #include <vtkProperty.h>
42 #include "VTKViewer_Actor.h"
44 #include "SVTK_DeviceActor.h"
45 #include "SALOME_Actor.h"
52 static int MYDEBUG = 0;
54 static int MYDEBUG = 0;
60 //vtkStandardNewMacro(SMESH_PreviewActorsCollection);
63 SMESH_PreviewActorsCollection
64 ::SMESH_PreviewActorsCollection()
66 if(MYDEBUG) MESSAGE("SMESH_PreviewActorsCollection - "<<this);
70 SMESH_PreviewActorsCollection
71 ::~SMESH_PreviewActorsCollection()
73 if(MYDEBUG) MESSAGE("~SMESH_PreviewActorsCollection - "<<this);
75 RemoveFromRender(myRenderer);
77 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
78 for ( ; iter != myMapOfActors.end(); ++iter )
79 if ( GEOM_Actor* anActor = iter.value() )
81 myMapOfActors.clear();
84 bool SMESH_PreviewActorsCollection::Init( const TopoDS_Shape& theShape, TopAbs_ShapeEnum theType, const QString& theEntry )
86 myMainShape = theShape;
87 myMapOfActors.clear();
88 myMapOfShapes.Clear();
90 if ( theShape.IsNull() )
93 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
94 anIO->setEntry( theEntry.toLatin1().constData() );
96 // get indexes of seleted elements
97 TopExp::MapShapes(theShape, myMapOfShapes);
99 TopExp_Explorer exp( theShape, theType );
100 for ( ; exp.More(); exp.Next() ) {
101 int index = myMapOfShapes.FindIndex( exp.Current() );
102 if ( index && !myMapOfActors.contains( index ) ) {
103 // create actor if the index is present
104 if ( GEOM_Actor* anActor = createActor( exp.Current().Oriented(TopAbs_FORWARD))) {
105 // Create new entry for actor
106 QString aString = theEntry;
107 aString += QString("_%1").arg( index ); // add index to actor entry
109 // Create interactive object
110 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
111 anIO->setEntry( aString.toLatin1().constData() );
114 anActor->SetVectorMode( theType==TopAbs_EDGE );
115 anActor->setIO( anIO );
116 anActor->SetSelector( mySelector );
117 anActor->SetPickable( true );
118 anActor->SetResolveCoincidentTopology( true );
120 // Add Actor to the Actors Map
121 myMapOfActors.insert(index, anActor);
125 mySelector->ClearIObjects();
130 GEOM_Actor* SMESH_PreviewActorsCollection::createActor(const TopoDS_Shape& shape)
132 GEOM_Actor* actor = GEOM_Actor::New();
133 actor->SetShape(shape,0,0);
137 vtkProperty* aProp = vtkProperty::New();
138 vtkProperty* aHLProp = vtkProperty::New();
139 vtkProperty* aPHLProp = vtkProperty::New();
141 aProp->SetColor( 255, 0, 0);
142 actor->SetProperty(aProp);
144 aHLProp->SetColor( 255, 255, 255);
145 actor->SetHighlightProperty(aHLProp);
147 aPHLProp->SetColor( 155, 155, 155);
148 aPHLProp->SetLineWidth ( 3 );
149 aPHLProp->SetOpacity ( 0.75 );
150 actor->SetPreHighlightProperty(aPHLProp);
160 GEOM_Actor* SMESH_PreviewActorsCollection::GetActorByIndex(int index)
162 return myMapOfActors.value(index);
165 int SMESH_PreviewActorsCollection::GetIndexByShape( const TopoDS_Shape& theShape )
167 return myMapOfShapes.FindIndex( theShape );
170 void SMESH_PreviewActorsCollection::AddToRender(vtkRenderer* theRenderer)
172 myRenderer = theRenderer;
174 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
175 for ( ; iter != myMapOfActors.end(); ++iter )
176 iter.value()->AddToRender( theRenderer );
179 void SMESH_PreviewActorsCollection::RemoveFromRender(vtkRenderer* theRenderer){
180 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
181 for ( ; iter != myMapOfActors.end(); ++iter )
182 iter.value()->RemoveFromRender( theRenderer );
185 void SMESH_PreviewActorsCollection::SetSelector(SVTK_Selector* theSelector)
187 mySelector = theSelector;
190 void SMESH_PreviewActorsCollection::HighlightAll( bool theHighlight ){
191 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
192 for ( ; iter != myMapOfActors.end(); ++iter )
193 iter.value()->Highlight( theHighlight );
196 void SMESH_PreviewActorsCollection::HighlightID( int index ){
197 GEOM_Actor* anActor = GetActorByIndex( index );
198 if ( anActor && !anActor->isHighlighted() )
199 anActor->Highlight( true );
202 void SMESH_PreviewActorsCollection::SetShown( bool shown ){
203 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
204 for ( ; iter != myMapOfActors.end(); ++iter )
205 iter.value()->SetVisibility( shown );