Version: 6.3.1

src/OBJECT/SMESH_PreviewActorsCollection.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SMESH OBJECT : interactive object for SMESH visualization
00021 //  File   : SMESH_PreviewActorsCollection.cxx
00022 //  Author : 
00023 //  Module : SMESH
00024 //
00025 #include "SMESH_PreviewActorsCollection.h"
00026 
00027 #include "utilities.h"
00028 
00029 #include "SALOME_InteractiveObject.hxx"
00030 
00031 // OCC includes
00032 #include <TopoDS.hxx>
00033 #include <TopExp.hxx>
00034 #include <TopExp_Explorer.hxx>
00035 
00036 // VTK includes
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 // QT
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 //vtkStandardNewMacro(SMESH_PreviewActorsCollection);
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   // get indexes of seleted elements
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       // create actor if the index is present
00104       if ( GEOM_Actor* anActor = createActor( exp.Current().Oriented(TopAbs_FORWARD))) {
00105         // Create new entry for actor
00106         QString aString = theEntry;
00107         aString += QString("_%1").arg( index ); // add index to actor entry
00108 
00109         // Create interactive object
00110         Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
00111         anIO->setEntry( aString.toLatin1().constData() );
00112 
00113         // Init Actor
00114         anActor->SetVectorMode( theType==TopAbs_EDGE );
00115         anActor->setIO( anIO );
00116         anActor->SetSelector( mySelector );
00117         anActor->SetPickable( true );
00118         anActor->SetResolveCoincidentTopology( true );
00119 
00120         // Add Actor to the Actors Map
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   //Color Properties
00136   /*    
00137         vtkProperty* aProp = vtkProperty::New();
00138         vtkProperty* aHLProp = vtkProperty::New();
00139         vtkProperty* aPHLProp = vtkProperty::New();
00140         
00141         aProp->SetColor( 255, 0, 0);
00142         actor->SetProperty(aProp);
00143 
00144         aHLProp->SetColor( 255, 255, 255);
00145         actor->SetHighlightProperty(aHLProp);
00146 
00147         aPHLProp->SetColor( 155, 155, 155);
00148         aPHLProp->SetLineWidth ( 3 );
00149         aPHLProp->SetOpacity ( 0.75 );
00150         actor->SetPreHighlightProperty(aPHLProp);
00151 
00152         aProp->Delete();
00153         aHLProp->Delete();
00154         aPHLProp->Delete();
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 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS