1 // Copyright (C) 2007-2010 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
23 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_Actor.cxx
25 // Author : Christophe ATTANASIO
30 \class GEOM_Actor GEOM_Actor.h
31 \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
33 #include "GEOM_Actor.h"
35 #include "GEOM_DeviceActor.h"
36 #include "GEOM_VertexSource.h"
37 #include "GEOM_EdgeSource.h"
38 #include "GEOM_WireframeFace.h"
39 #include "GEOM_ShadingFace.h"
40 #include "SVTK_Actor.h"
42 #include <vtkObjectFactory.h>
43 #include <vtkRenderer.h>
44 #include <vtkProperty.h>
45 #include <vtkPointPicker.h>
46 #include <vtkCellPicker.h>
48 #include <TopAbs_ShapeEnum.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <Poly_Triangulation.hxx>
51 #include <BRepMesh_IncrementalMesh.hxx>
52 #include <Bnd_Box.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepBndLib.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopoDS_Iterator.hxx>
60 #include <vtkPolyDataWriter.h>
62 #include <vtkAppendPolyData.h>
63 #include <vtkPolyDataMapper.h>
64 #include <vtkPolyData.h>
65 #include <vtkTransform.h>
66 #include <vtkMatrix4x4.h>
68 #include <vtkCamera.h>
70 #include "utilities.h"
72 #include "SALOME_InteractiveObject.hxx"
74 //vtkStandardNewMacro(GEOM_Actor);
80 GEOM_Actor::GEOM_Actor():
81 // myDisplayMode(eWireframe),
84 myVertexActor(GEOM_DeviceActor::New(),true),
85 myVertexSource(GEOM_VertexSource::New(),true),
87 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
88 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
90 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
91 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
93 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
94 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
96 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
97 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
99 myShadingFaceActor(GEOM_DeviceActor::New(),true),
100 myShadingFaceSource(GEOM_ShadingFace::New(),true),
102 myHighlightActor(GEOM_DeviceActor::New(),true),
103 myAppendFilter(vtkAppendPolyData::New(),true),
104 myPolyDataMapper(vtkPolyDataMapper::New(),true),
106 myHighlightProp(vtkProperty::New()),
107 myPreHighlightProp(vtkProperty::New()),
108 myShadingFaceProp(vtkProperty::New()),
112 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
115 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
116 vtkProperty* aProperty;
118 myHighlightProp->SetAmbient(0.5);
119 myHighlightProp->SetDiffuse(0.3);
120 myHighlightProp->SetSpecular(0.2);
121 myHighlightProp->SetRepresentationToSurface();
122 myHighlightProp->SetAmbientColor(1, 1, 1);
123 myHighlightProp->SetDiffuseColor(1, 1, 1);
124 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
125 myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
126 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
128 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
130 myPreHighlightProp->SetColor(0,1,1);
131 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
132 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
133 myPreHighlightProp->SetRepresentationToWireframe();
135 myAppendFilter->AddInput(myVertexSource->GetOutput());
136 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
137 aProperty = myVertexActor->GetProperty();
138 aProperty->SetRepresentation(VTK_POINTS);
139 aProperty->SetPointSize(3);
140 aProperty->SetColor(1, 1, 0);
142 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
143 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
144 aProperty = myIsolatedEdgeActor->GetProperty();
145 aProperty->SetRepresentation(VTK_WIREFRAME);
146 aProperty->SetColor(1, 0, 0);
148 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
149 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
150 aProperty = myOneFaceEdgeActor->GetProperty();
151 aProperty->SetRepresentation(VTK_WIREFRAME);
152 aProperty->SetColor(0, 1, 0);
154 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
155 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
156 aProperty = mySharedEdgeActor->GetProperty();
157 aProperty->SetRepresentation(VTK_WIREFRAME);
158 aProperty->SetColor(1, 1, 0);
160 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
161 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
162 aProperty = myWireframeFaceActor->GetProperty();
163 aProperty->SetRepresentation(VTK_WIREFRAME);
164 aProperty->SetColor(0.5, 0.5, 0.5);
166 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
168 myShadingFaceProp->SetRepresentation(VTK_SURFACE);
169 myShadingFaceProp->SetInterpolationToGouraud();
170 myShadingFaceProp->SetAmbient(1.0);
171 myShadingFaceProp->SetDiffuse(1.0);
172 myShadingFaceProp->SetSpecular(0.4);
173 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
174 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
175 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
177 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
179 // Toggle display mode
180 setDisplayMode(0); // WIRE FRAME
185 GEOM_Actor::~GEOM_Actor()
188 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
190 myHighlightProp->Delete();
191 myPreHighlightProp->Delete();
192 myShadingFaceProp->Delete();
199 GEOM_Actor* anObject = new GEOM_Actor();
200 anObject->SetMapper(anObject->myPolyDataMapper.Get());
205 void Write(vtkPolyData* theDataSet, const char* theFileName){
206 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
207 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
208 aWriter->SetInput(theDataSet);
209 aWriter->SetFileName(theFileName);
218 this->myVertexSource->Modified();
219 this->myIsolatedEdgeSource->Modified();
220 this->myOneFaceEdgeSource->Modified();
221 this->mySharedEdgeSource->Modified();
222 this->myWireframeFaceSource->Modified();
223 this->myShadingFaceSource->Modified();
228 SetMapper(vtkMapper* theMapper)
230 SALOME_Actor::SetMapper(theMapper);
235 AddToRender(vtkRenderer* theRenderer)
237 //SALOME_Actor::AddToRender(theRenderer);
239 theRenderer->AddActor(this);
241 this->myHighlightActor->AddToRender(theRenderer);
244 myShadingFaceActor->AddToRender(theRenderer);
245 myWireframeFaceActor->AddToRender(theRenderer);
247 mySharedEdgeActor->AddToRender(theRenderer);
248 myOneFaceEdgeActor->AddToRender(theRenderer);
249 myIsolatedEdgeActor->AddToRender(theRenderer);
251 myVertexActor->AddToRender(theRenderer);
256 RemoveFromRender(vtkRenderer* theRenderer)
258 //SALOME_Actor::RemoveFromRender(theRenderer);
261 theRenderer->RemoveActor(this);
263 myHighlightActor->RemoveFromRender(theRenderer);
264 myShadingFaceActor->RemoveFromRender(theRenderer);
265 myWireframeFaceActor->RemoveFromRender(theRenderer);
267 mySharedEdgeActor->RemoveFromRender(theRenderer);
268 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
269 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
271 myVertexActor->RemoveFromRender(theRenderer);
275 SetVisibility(false);
280 setDisplayMode(int theMode)
283 MESSAGE ( "GEOM_Actor::SetDisplayMode = "<<theMode );
285 VTKViewer_Actor::setDisplayMode(theMode);
286 SetVisibility(GetVisibility());
291 SetSelected(bool theIsSelected)
294 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
297 myIsSelected = theIsSelected;
298 SetVisibility(GetVisibility());
303 SetVisibility(int theVisibility)
306 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
307 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
310 SALOME_Actor::SetVisibility(theVisibility);
312 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
314 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected));
315 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
317 mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
318 myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
319 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
321 myVertexActor->SetVisibility(theVisibility && !myIsSelected);// must be added new mode points
327 ::SetNbIsos(const int theNb[2])
329 myWireframeFaceSource->SetNbIso(theNb);
334 ::GetNbIsos(int &theNbU,int &theNbV)
336 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
341 ::SetVectorMode(bool theMode)
343 myVectorMode = theMode;
344 myIsolatedEdgeSource->SetVectorMode(theMode);
345 myOneFaceEdgeSource->SetVectorMode(theMode);
346 mySharedEdgeSource->SetVectorMode(theMode);
359 MeshShape(const TopoDS_Shape& theShape,
360 float& theDeflection,
363 static Standard_Real RELATIVE_DEFLECTION = 0.0001;
364 Standard_Real aDeflection = theDeflection;
366 if(theDeflection <= 0) { // Compute default theDeflection
368 BRepBndLib::Add(theShape, B);
369 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
370 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
371 Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
372 (aYmax-aYmin)*(aYmax-aYmin) +
373 (aZmax-aZmin)*(aZmax-aZmin);
374 aDiagonal = sqrt(aDiagonal);
375 aDeflection = aDiagonal*RELATIVE_DEFLECTION;
378 theDeflection = RELATIVE_DEFLECTION;
380 theDeflection = aDeflection;
383 BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
388 SetDeflection(float theDeflection, bool theIsRelative)
390 myDeflection = theDeflection;
391 myIsRelative = theIsRelative;
393 MeshShape(myShape,myDeflection,myIsRelative);
398 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
405 myVertexSource->Clear();
406 myIsolatedEdgeSource->Clear();
407 myOneFaceEdgeSource->Clear();
408 mySharedEdgeSource->Clear();
409 myWireframeFaceSource->Clear();
410 myShadingFaceSource->Clear();
412 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
413 for (; aVertexExp.More(); aVertexExp.Next())
415 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
416 myVertexSource->AddVertex(aVertex);
418 SetDeflection(theDeflection, theIsRelative);
420 // look if edges are free or shared
421 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
422 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
424 SetShape(theShape,anEdgeMap,theIsVector);
426 myIsolatedEdgeSource->IsEmpty() &&
427 myOneFaceEdgeSource->IsEmpty() &&
428 mySharedEdgeSource->IsEmpty() &&
429 myWireframeFaceSource->IsEmpty() &&
430 myShadingFaceSource->IsEmpty();
433 if((bool)myShape.Infinite() || isOnlyVertex ){
434 myVertexActor->GetDeviceActor()->SetInfinitive(true);
435 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
439 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
440 const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
443 if (theShape.ShapeType() == TopAbs_COMPOUND) {
444 TopoDS_Iterator anItr(theShape);
445 for (; anItr.More(); anItr.Next()) {
446 SetShape(anItr.Value(),theEdgeMap,theIsVector);
450 switch (theShape.ShapeType()) {
452 TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
453 for (; anEdgeExp.More(); anEdgeExp.Next()){
454 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
455 if (!BRep_Tool::Degenerated(anEdge))
456 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
461 const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
462 if (!BRep_Tool::Degenerated(anEdge))
463 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
466 case TopAbs_VERTEX: {
470 TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
471 for(; aFaceExp.More(); aFaceExp.Next()) {
472 const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
473 myWireframeFaceSource->AddFace(aFace);
474 myShadingFaceSource->AddFace(aFace);
475 TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
476 for(; anEdgeExp.More(); anEdgeExp.Next()) {
477 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
478 if(!BRep_Tool::Degenerated(anEdge)){
479 // compute the number of faces
480 int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
482 case 0: // isolated edge
483 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
485 case 1: // edge in only one face
486 myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
488 default: // edge shared by at least two faces
489 mySharedEdgeSource->AddEdge(anEdge,theIsVector);
499 void GEOM_Actor::setDeflection(double adef) {
501 MESSAGE ( "GEOM_Actor::setDeflection" );
503 SetDeflection((float)adef,GetIsRelative());
507 // warning! must be checked!
508 // SetHighlightProperty
509 // SetWireframeProperty
510 // SetShadingProperty
512 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
515 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
517 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
521 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
524 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
527 myWireframeFaceActor->SetProperty(Prop);
530 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
533 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
535 myShadingFaceProp->DeepCopy(Prop);
539 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
542 MESSAGE ( "GEOM_Actor::Render" );
548 /* render the property */
549 if (!this->Property) {
550 // force creation of a property
552 this->Property->SetInterpolation(1);
553 this->Property->SetRepresentationToSurface();
554 this->Property->SetAmbient(0.3);
555 this->Property->SetAmbientColor(0.88,0.86,0.2);
556 this->Property->SetDiffuseColor(0.99,0.7,0.21);
557 this->Property->SetSpecularColor(0.99,0.98,0.83);
560 switch(myDisplayMode){
562 myPreHighlightProp->SetRepresentationToWireframe();
563 myHighlightProp->SetRepresentationToWireframe();
566 myPreHighlightProp->SetRepresentationToSurface();
567 myHighlightProp->SetRepresentationToSurface();
573 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
574 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
576 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
577 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
581 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
582 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
585 this->Property->Render(this, ren);
586 if (this->BackfaceProperty) {
587 this->BackfaceProperty->BackfaceRender(this, ren);
588 this->Device->SetBackfaceProperty(this->BackfaceProperty);
590 this->Device->SetProperty(this->Property);
591 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
593 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
594 static vtkFloatingPointType delta = 0.01;
595 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
596 ren->ViewToWorld(X1,Y1,Z1);
597 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
598 ren->ViewToWorld(X2,Y2,Z2);
599 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
600 this->SetScale(Z2*delta);
602 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
603 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
604 this->Device->SetUserMatrix(aMatrix);
605 this->Device->Render(ren,theMapper);
608 this->Device->Render(ren, theMapper);
611 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
614 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
620 void GEOM_Actor::ShallowCopy(vtkProp *prop)
623 MESSAGE ( "GEOM_Actor::ShallowCopy" );
625 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
628 this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
632 this->SALOME_Actor::ShallowCopy(prop);
635 const TopoDS_Shape& GEOM_Actor::getTopo() {
637 MESSAGE ( "GEOM_Actor::getTopo" );
642 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
643 int imode, bool isVector)
646 MESSAGE ( "GEOM_Actor::setInputShape" );
650 double GEOM_Actor::getDeflection()
653 MESSAGE ( "GEOM_Actor::getDeflection" );
655 return (double) GetDeflection();
659 double GEOM_Actor::isVector()
662 MESSAGE ( "GEOM_Actor::isVector" );
667 void GEOM_Actor::SubShapeOn()
670 MESSAGE ( "GEOM_Actor::SubShapeOn" );
674 void GEOM_Actor::SubShapeOff()
677 MESSAGE ( "GEOM_Actor::SubShapeOff" );
681 void GEOM_Actor::highlight(bool highlight)
684 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
686 SALOME_Actor::highlight(highlight);
689 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
692 myShadingFaceProp->SetOpacity(opa);
693 myHighlightProp->SetOpacity(opa);
694 myPreHighlightProp->SetOpacity(opa);
695 myVertexActor->GetProperty()->SetOpacity(opa);
698 vtkFloatingPointType GEOM_Actor::GetOpacity()
701 return myShadingFaceProp->GetOpacity();
704 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
707 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
708 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
709 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
710 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
711 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
714 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
717 vtkFloatingPointType aRGB[3];
718 myShadingFaceProp->GetColor(aRGB);
724 bool GEOM_Actor::IsInfinitive()
726 return ((bool)myShape.Infinite() || isOnlyVertex);
730 To map current selection to VTK representation
734 ::Highlight(bool theIsHighlight)
736 myIsSelected = theIsHighlight;
738 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
741 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
742 SetVisibility(GetVisibility());
746 To process prehighlight (called from SVTK_InteractorStyle)
750 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
751 SVTK_SelectionEvent* theSelectionEvent,
755 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
758 if ( !GetPickable() )
761 myPreHighlightActor->SetVisibility( false );
762 bool anIsPreselected = myIsPreselected;
764 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
765 bool anIsChanged = (mySelectionMode != aSelectionMode);
767 if( !theIsHighlight ) {
768 SetPreSelected( false );
770 switch(aSelectionMode){
771 case ActorSelection :
773 // cout << "=============== " << myIO->getEntry() << endl;
774 int nbio = mySelector->IObjectCount();
775 // cout << " nbio = " << nbio << endl;
777 if( !mySelector->IsSelected( myIO ) ) {
778 // printf ("!!!!!!!!!!!!!!!!\n");
779 SetPreSelected( true );
787 mySelectionMode = aSelectionMode;
788 anIsChanged |= (anIsPreselected != myIsPreselected);
790 SetVisibility(GetVisibility());
795 To process highlight (called from SVTK_InteractorStyle)
799 ::Highlight(vtkInteractorStyle *theInteractorStyle,
800 SVTK_SelectionEvent* theSelectionEvent,
803 // define the selection of object
805 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
807 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
808 SetSelected(theIsHighlight);
810 SetPreSelected(false);
816 // Copy the follower's composite 4x4 matrix into the matrix provided.
817 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
820 double Rx[3], Ry[3], Rz[3], p1[3];
821 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
825 this->GetOrientation();
826 this->Transform->Push();
827 this->Transform->PostMultiply();
828 this->Transform->Identity();
830 // apply user defined matrix last if there is one
831 if (this->UserMatrix)
833 this->Transform->Concatenate(this->UserMatrix);
836 this->Transform->Translate(-this->Origin[0],
840 this->Transform->Scale(this->Scale[0],
845 this->Transform->RotateY(this->Orientation[1]);
846 this->Transform->RotateX(this->Orientation[0]);
847 this->Transform->RotateZ(this->Orientation[2]);
853 pos = theCam->GetPosition();
854 vup = theCam->GetViewUp();
856 if (theCam->GetParallelProjection())
858 theCam->GetDirectionOfProjection(Rz);
863 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
864 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
865 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
866 for (i = 0; i < 3; i++)
868 Rz[i] = (pos[i] - this->Position[i])/distance;
872 vtkMath::Cross(vup,Rz,Rx);
873 vtkMath::Normalize(Rx);
874 vtkMath::Cross(Rz,Rx,Ry);
876 matrix->Element[0][0] = Rx[0];
877 matrix->Element[1][0] = Rx[1];
878 matrix->Element[2][0] = Rx[2];
879 matrix->Element[0][1] = Ry[0];
880 matrix->Element[1][1] = Ry[1];
881 matrix->Element[2][1] = Ry[2];
882 matrix->Element[0][2] = Rz[0];
883 matrix->Element[1][2] = Rz[1];
884 matrix->Element[2][2] = Rz[2];
886 this->Transform->Concatenate(matrix);
889 // translate to projection reference point PRP
890 // this is the camera's position blasted through
891 // the current matrix
892 p1[0] = this->Origin[0] + this->Position[0];
893 p1[1] = this->Origin[1] + this->Position[1];
894 p1[2] = this->Origin[2] + this->Position[2];
896 this->Transform->Translate(p1[0],p1[1],p1[2]);
897 this->Transform->GetMatrix(result);
900 this->Transform->Pop();