1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH OBJECT : interactive object for SMESH visualization
23 // File : SMESH_PreviewActorsCollection.cxx
28 #include "SMESH_PreviewActorsCollection.h"
30 #include "utilities.h"
32 #include "SALOME_InteractiveObject.hxx"
37 #include <TopExp_Explorer.hxx>
40 #include <vtkUnstructuredGrid.h>
41 #include <vtkScalarBarActor.h>
43 #include <vtkRenderer.h>
44 #include <vtkProperty.h>
46 #include "VTKViewer_Actor.h"
48 #include "SVTK_DeviceActor.h"
49 #include "SALOME_Actor.h"
56 static int MYDEBUG = 0;
58 static int MYDEBUG = 0;
64 //vtkStandardNewMacro(SMESH_PreviewActorsCollection);
67 SMESH_PreviewActorsCollection
68 ::SMESH_PreviewActorsCollection()
70 if(MYDEBUG) MESSAGE("SMESH_PreviewActorsCollection - "<<this);
74 SMESH_PreviewActorsCollection
75 ::~SMESH_PreviewActorsCollection()
77 if(MYDEBUG) MESSAGE("~SMESH_PreviewActorsCollection - "<<this);
79 RemoveFromRender(myRenderer);
81 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
82 for ( ; iter != myMapOfActors.end(); ++iter )
83 if ( GEOM_Actor* anActor = iter.value() )
85 myMapOfActors.clear();
88 bool SMESH_PreviewActorsCollection::Init( const TopoDS_Shape& theShape, TopAbs_ShapeEnum theType, const QString& theEntry )
90 myMainShape = theShape;
91 myMapOfActors.clear();
92 myMapOfShapes.Clear();
94 if ( theShape.IsNull() )
97 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
98 anIO->setEntry( theEntry.toLatin1().constData() );
100 // get indexes of seleted elements
101 TopExp::MapShapes(theShape, myMapOfShapes);
103 TopExp_Explorer exp( theShape, theType );
104 for ( ; exp.More(); exp.Next() ) {
105 int index = myMapOfShapes.FindIndex( exp.Current() );
106 if ( index && !myMapOfActors.contains( index ) ) {
107 // create actor if the index is present
108 if ( GEOM_Actor* anActor = createActor( exp.Current() )) {
109 // Create new entry for actor
110 QString aString = theEntry;
111 aString += QString("_%1").arg( index ); // add index to actor entry
113 // Create interactive object
114 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
115 anIO->setEntry( aString.toLatin1().constData() );
118 anActor->SetVectorMode( true );
119 anActor->setIO( anIO );
120 anActor->SetSelector( mySelector );
121 anActor->SetPickable( true );
122 anActor->SetResolveCoincidentTopology( true );
124 // Add Actor to the Actors Map
125 myMapOfActors.insert(index, anActor);
129 mySelector->ClearIObjects();
134 GEOM_Actor* SMESH_PreviewActorsCollection::createActor(const TopoDS_Shape& shape)
136 GEOM_Actor* actor = GEOM_Actor::New();
137 actor->SetShape(shape,0,0);
141 vtkProperty* aProp = vtkProperty::New();
142 vtkProperty* aHLProp = vtkProperty::New();
143 vtkProperty* aPHLProp = vtkProperty::New();
145 aProp->SetColor( 255, 0, 0);
146 actor->SetProperty(aProp);
148 aHLProp->SetColor( 255, 255, 255);
149 actor->SetHighlightProperty(aHLProp);
151 aPHLProp->SetColor( 155, 155, 155);
152 aPHLProp->SetLineWidth ( 3 );
153 aPHLProp->SetOpacity ( 0.75 );
154 actor->SetPreHighlightProperty(aPHLProp);
164 GEOM_Actor* SMESH_PreviewActorsCollection::GetActorByIndex(int index)
166 return myMapOfActors.value(index);
169 int SMESH_PreviewActorsCollection::GetIndexByShape( const TopoDS_Shape& theShape )
171 return myMapOfShapes.FindIndex( theShape );
174 void SMESH_PreviewActorsCollection::AddToRender(vtkRenderer* theRenderer)
176 myRenderer = theRenderer;
178 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
179 for ( ; iter != myMapOfActors.end(); ++iter )
180 iter.value()->AddToRender( theRenderer );
183 void SMESH_PreviewActorsCollection::RemoveFromRender(vtkRenderer* theRenderer){
184 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
185 for ( ; iter != myMapOfActors.end(); ++iter )
186 iter.value()->RemoveFromRender( theRenderer );
189 void SMESH_PreviewActorsCollection::SetSelector(SVTK_Selector* theSelector)
191 mySelector = theSelector;
194 void SMESH_PreviewActorsCollection::HighlightAll( bool theHighlight ){
195 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
196 for ( ; iter != myMapOfActors.end(); ++iter )
197 iter.value()->Highlight( theHighlight );
200 void SMESH_PreviewActorsCollection::HighlightID( int index ){
201 GEOM_Actor* anActor = GetActorByIndex( index );
202 if ( anActor && !anActor->isHighlighted() )
203 anActor->Highlight( true );
206 void SMESH_PreviewActorsCollection::SetShown( bool shown ){
207 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
208 for ( ; iter != myMapOfActors.end(); ++iter )
209 iter.value()->SetVisibility( shown );