Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "SMESH_PreviewActorsCollection.h"
00026
00027 #include "utilities.h"
00028
00029 #include "SALOME_InteractiveObject.hxx"
00030
00031
00032 #include <TopoDS.hxx>
00033 #include <TopExp.hxx>
00034 #include <TopExp_Explorer.hxx>
00035
00036
00037 #include <vtkUnstructuredGrid.h>
00038 #include <vtkPlane.h>
00039 #include <vtkRenderer.h>
00040 #include <vtkProperty.h>
00041
00042 #include "VTKViewer_Actor.h"
00043
00044 #include "SVTK_DeviceActor.h"
00045 #include "SALOME_Actor.h"
00046
00047
00048 #include <QString>
00049 #include <QColor>
00050
00051 #ifdef _DEBUG_
00052 static int MYDEBUG = 0;
00053 #else
00054 static int MYDEBUG = 0;
00055 #endif
00056
00057 using namespace std;
00058
00059
00060
00061
00062
00063 SMESH_PreviewActorsCollection
00064 ::SMESH_PreviewActorsCollection()
00065 {
00066 if(MYDEBUG) MESSAGE("SMESH_PreviewActorsCollection - "<<this);
00067 }
00068
00069
00070 SMESH_PreviewActorsCollection
00071 ::~SMESH_PreviewActorsCollection()
00072 {
00073 if(MYDEBUG) MESSAGE("~SMESH_PreviewActorsCollection - "<<this);
00074 if (myRenderer)
00075 RemoveFromRender(myRenderer);
00076
00077 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
00078 for ( ; iter != myMapOfActors.end(); ++iter )
00079 if ( GEOM_Actor* anActor = iter.value() )
00080 anActor->Delete();
00081 myMapOfActors.clear();
00082 }
00083
00084 bool SMESH_PreviewActorsCollection::Init( const TopoDS_Shape& theShape, TopAbs_ShapeEnum theType, const QString& theEntry )
00085 {
00086 myMainShape = theShape;
00087 myMapOfActors.clear();
00088 myMapOfShapes.Clear();
00089
00090 if ( theShape.IsNull() )
00091 return false;
00092
00093 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
00094 anIO->setEntry( theEntry.toLatin1().constData() );
00095
00096
00097 TopExp::MapShapes(theShape, myMapOfShapes);
00098
00099 TopExp_Explorer exp( theShape, theType );
00100 for ( ; exp.More(); exp.Next() ) {
00101 int index = myMapOfShapes.FindIndex( exp.Current() );
00102 if ( index && !myMapOfActors.contains( index ) ) {
00103
00104 if ( GEOM_Actor* anActor = createActor( exp.Current().Oriented(TopAbs_FORWARD))) {
00105
00106 QString aString = theEntry;
00107 aString += QString("_%1").arg( index );
00108
00109
00110 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
00111 anIO->setEntry( aString.toLatin1().constData() );
00112
00113
00114 anActor->SetVectorMode( theType==TopAbs_EDGE );
00115 anActor->setIO( anIO );
00116 anActor->SetSelector( mySelector );
00117 anActor->SetPickable( true );
00118 anActor->SetResolveCoincidentTopology( true );
00119
00120
00121 myMapOfActors.insert(index, anActor);
00122 }
00123 }
00124 }
00125 mySelector->ClearIObjects();
00126
00127 return true;
00128 }
00129
00130 GEOM_Actor* SMESH_PreviewActorsCollection::createActor(const TopoDS_Shape& shape)
00131 {
00132 GEOM_Actor* actor = GEOM_Actor::New();
00133 actor->SetShape(shape,0,0);
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 return actor;
00158 }
00159
00160 GEOM_Actor* SMESH_PreviewActorsCollection::GetActorByIndex(int index)
00161 {
00162 return myMapOfActors.value(index);
00163 }
00164
00165 int SMESH_PreviewActorsCollection::GetIndexByShape( const TopoDS_Shape& theShape )
00166 {
00167 return myMapOfShapes.FindIndex( theShape );
00168 }
00169
00170 void SMESH_PreviewActorsCollection::AddToRender(vtkRenderer* theRenderer)
00171 {
00172 myRenderer = theRenderer;
00173
00174 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
00175 for ( ; iter != myMapOfActors.end(); ++iter )
00176 iter.value()->AddToRender( theRenderer );
00177 }
00178
00179 void SMESH_PreviewActorsCollection::RemoveFromRender(vtkRenderer* theRenderer){
00180 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
00181 for ( ; iter != myMapOfActors.end(); ++iter )
00182 iter.value()->RemoveFromRender( theRenderer );
00183 }
00184
00185 void SMESH_PreviewActorsCollection::SetSelector(SVTK_Selector* theSelector)
00186 {
00187 mySelector = theSelector;
00188 }
00189
00190 void SMESH_PreviewActorsCollection::HighlightAll( bool theHighlight ){
00191 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
00192 for ( ; iter != myMapOfActors.end(); ++iter )
00193 iter.value()->Highlight( theHighlight );
00194 }
00195
00196 void SMESH_PreviewActorsCollection::HighlightID( int index ){
00197 GEOM_Actor* anActor = GetActorByIndex( index );
00198 if ( anActor && !anActor->isHighlighted() )
00199 anActor->Highlight( true );
00200 }
00201
00202 void SMESH_PreviewActorsCollection::SetShown( bool shown ){
00203 QMap<int, GEOM_Actor*>::iterator iter = myMapOfActors.begin();
00204 for ( ; iter != myMapOfActors.end(); ++iter )
00205 iter.value()->SetVisibility( shown );
00206 }