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
21 // GEOM OBJECT : interactive object for Geometry entities visualization
22 // File : GEOM_Actor.cxx
23 // Author : Christophe ATTANASIO
28 \class GEOM_Actor GEOM_Actor.h
29 \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
31 #include "GEOM_Actor.h"
33 #include "GEOM_DeviceActor.h"
34 #include "GEOM_VertexSource.h"
35 #include "GEOM_EdgeSource.h"
36 #include "GEOM_WireframeFace.h"
37 #include "GEOM_ShadingFace.h"
38 #include "SVTK_Actor.h"
40 #include <vtkObjectFactory.h>
41 #include <vtkRenderer.h>
42 #include <vtkProperty.h>
43 #include <vtkPointPicker.h>
44 #include <vtkCellPicker.h>
46 #include <TopAbs_ShapeEnum.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <Poly_Triangulation.hxx>
49 #include <BRepMesh_IncrementalMesh.hxx>
50 #include <Bnd_Box.hxx>
52 #include <BRep_Tool.hxx>
53 #include <BRepBndLib.hxx>
54 #include <TopTools_ListOfShape.hxx>
55 #include <TopoDS_Iterator.hxx>
58 #include <vtkPolyDataWriter.h>
60 #include <vtkAppendPolyData.h>
61 #include <vtkPolyDataMapper.h>
62 #include <vtkPolyData.h>
63 #include <vtkTransform.h>
64 #include <vtkMatrix4x4.h>
66 #include <vtkCamera.h>
68 #include "utilities.h"
70 #include "SALOME_InteractiveObject.hxx"
72 //vtkStandardNewMacro(GEOM_Actor);
78 GEOM_Actor::GEOM_Actor():
79 // myDisplayMode(eWireframe),
82 myVertexActor(GEOM_DeviceActor::New(),true),
83 myVertexSource(GEOM_VertexSource::New(),true),
85 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
86 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
88 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
89 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
91 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
92 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
94 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
95 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
97 myShadingFaceActor(GEOM_DeviceActor::New(),true),
98 myShadingFaceSource(GEOM_ShadingFace::New(),true),
100 myHighlightActor(GEOM_DeviceActor::New(),true),
101 myAppendFilter(vtkAppendPolyData::New(),true),
102 myPolyDataMapper(vtkPolyDataMapper::New(),true),
104 myHighlightProp(vtkProperty::New()),
105 myPreHighlightProp(vtkProperty::New()),
106 myShadingFaceProp(vtkProperty::New()),
110 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
113 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
114 vtkProperty* aProperty;
116 myHighlightProp->SetAmbient(0.5);
117 myHighlightProp->SetDiffuse(0.3);
118 myHighlightProp->SetSpecular(0.2);
119 myHighlightProp->SetRepresentationToSurface();
120 myHighlightProp->SetAmbientColor(1, 1, 1);
121 myHighlightProp->SetDiffuseColor(1, 1, 1);
122 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
123 myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
124 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
126 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
128 myPreHighlightProp->SetColor(0,1,1);
129 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
130 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
131 myPreHighlightProp->SetRepresentationToWireframe();
133 myAppendFilter->AddInput(myVertexSource->GetOutput());
134 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
135 aProperty = myVertexActor->GetProperty();
136 aProperty->SetRepresentation(VTK_POINTS);
137 aProperty->SetPointSize(3);
138 aProperty->SetColor(1, 1, 0);
140 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
141 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
142 aProperty = myIsolatedEdgeActor->GetProperty();
143 aProperty->SetRepresentation(VTK_WIREFRAME);
144 aProperty->SetColor(1, 0, 0);
146 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
147 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
148 aProperty = myOneFaceEdgeActor->GetProperty();
149 aProperty->SetRepresentation(VTK_WIREFRAME);
150 aProperty->SetColor(0, 1, 0);
152 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
153 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
154 aProperty = mySharedEdgeActor->GetProperty();
155 aProperty->SetRepresentation(VTK_WIREFRAME);
156 aProperty->SetColor(1, 1, 0);
158 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
159 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
160 aProperty = myWireframeFaceActor->GetProperty();
161 aProperty->SetRepresentation(VTK_WIREFRAME);
162 aProperty->SetColor(0.5, 0.5, 0.5);
164 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
166 myShadingFaceProp->SetRepresentation(VTK_SURFACE);
167 myShadingFaceProp->SetInterpolationToGouraud();
168 myShadingFaceProp->SetAmbient(1.0);
169 myShadingFaceProp->SetDiffuse(1.0);
170 myShadingFaceProp->SetSpecular(0.4);
171 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
172 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
173 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
175 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
177 // Toggle display mode
178 setDisplayMode(0); // WIRE FRAME
183 GEOM_Actor::~GEOM_Actor()
186 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
188 myHighlightProp->Delete();
189 myPreHighlightProp->Delete();
190 myShadingFaceProp->Delete();
197 GEOM_Actor* anObject = new GEOM_Actor();
198 anObject->SetMapper(anObject->myPolyDataMapper.Get());
203 void Write(vtkPolyData* theDataSet, const char* theFileName){
204 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
205 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
206 aWriter->SetInput(theDataSet);
207 aWriter->SetFileName(theFileName);
216 this->myVertexSource->Modified();
217 this->myIsolatedEdgeSource->Modified();
218 this->myOneFaceEdgeSource->Modified();
219 this->mySharedEdgeSource->Modified();
220 this->myWireframeFaceSource->Modified();
221 this->myShadingFaceSource->Modified();
226 SetMapper(vtkMapper* theMapper)
228 SALOME_Actor::SetMapper(theMapper);
233 AddToRender(vtkRenderer* theRenderer)
235 //SALOME_Actor::AddToRender(theRenderer);
237 theRenderer->AddActor(this);
239 this->myHighlightActor->AddToRender(theRenderer);
242 myShadingFaceActor->AddToRender(theRenderer);
243 myWireframeFaceActor->AddToRender(theRenderer);
245 mySharedEdgeActor->AddToRender(theRenderer);
246 myOneFaceEdgeActor->AddToRender(theRenderer);
247 myIsolatedEdgeActor->AddToRender(theRenderer);
249 myVertexActor->AddToRender(theRenderer);
254 RemoveFromRender(vtkRenderer* theRenderer)
256 //SALOME_Actor::RemoveFromRender(theRenderer);
259 theRenderer->RemoveActor(this);
261 myHighlightActor->RemoveFromRender(theRenderer);
262 myShadingFaceActor->RemoveFromRender(theRenderer);
263 myWireframeFaceActor->RemoveFromRender(theRenderer);
265 mySharedEdgeActor->RemoveFromRender(theRenderer);
266 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
267 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
269 myVertexActor->RemoveFromRender(theRenderer);
273 SetVisibility(false);
278 setDisplayMode(int theMode)
281 MESSAGE ( "GEOM_Actor::SetDisplayMode = "<<theMode );
283 VTKViewer_Actor::setDisplayMode(theMode);
284 SetVisibility(GetVisibility());
289 SetSelected(bool theIsSelected)
292 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
295 myIsSelected = theIsSelected;
296 SetVisibility(GetVisibility());
301 SetVisibility(int theVisibility)
304 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
305 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
308 SALOME_Actor::SetVisibility(theVisibility);
310 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
312 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected));
313 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
315 mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
316 myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
317 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
319 myVertexActor->SetVisibility(theVisibility && !myIsSelected);// must be added new mode points
325 ::SetNbIsos(const int theNb[2])
327 myWireframeFaceSource->SetNbIso(theNb);
332 ::GetNbIsos(int &theNbU,int &theNbV)
334 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
339 ::SetVectorMode(bool theMode)
341 myVectorMode = theMode;
342 myIsolatedEdgeSource->SetVectorMode(theMode);
343 myOneFaceEdgeSource->SetVectorMode(theMode);
344 mySharedEdgeSource->SetVectorMode(theMode);
357 MeshShape(const TopoDS_Shape& theShape,
358 float& theDeflection,
361 static Standard_Real RELATIVE_DEFLECTION = 0.0001;
362 Standard_Real aDeflection = theDeflection;
364 if(theDeflection <= 0) { // Compute default theDeflection
366 BRepBndLib::Add(theShape, B);
367 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
368 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
369 Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
370 (aYmax-aYmin)*(aYmax-aYmin) +
371 (aZmax-aZmin)*(aZmax-aZmin);
372 aDiagonal = sqrt(aDiagonal);
373 aDeflection = aDiagonal*RELATIVE_DEFLECTION;
376 theDeflection = RELATIVE_DEFLECTION;
378 theDeflection = aDeflection;
381 BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
386 SetDeflection(float theDeflection, bool theIsRelative)
388 myDeflection = theDeflection;
389 myIsRelative = theIsRelative;
391 MeshShape(myShape,myDeflection,myIsRelative);
396 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
403 myVertexSource->Clear();
404 myIsolatedEdgeSource->Clear();
405 myOneFaceEdgeSource->Clear();
406 mySharedEdgeSource->Clear();
407 myWireframeFaceSource->Clear();
408 myShadingFaceSource->Clear();
410 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
411 for (; aVertexExp.More(); aVertexExp.Next())
413 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
414 myVertexSource->AddVertex(aVertex);
416 SetDeflection(theDeflection, theIsRelative);
418 // look if edges are free or shared
419 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
420 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
422 SetShape(theShape,anEdgeMap,theIsVector);
424 myIsolatedEdgeSource->IsEmpty() &&
425 myOneFaceEdgeSource->IsEmpty() &&
426 mySharedEdgeSource->IsEmpty() &&
427 myWireframeFaceSource->IsEmpty() &&
428 myShadingFaceSource->IsEmpty();
431 if((bool)myShape.Infinite() || isOnlyVertex ){
432 myVertexActor->GetDeviceActor()->SetInfinitive(true);
433 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
437 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
438 const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
441 if (theShape.ShapeType() == TopAbs_COMPOUND) {
442 TopoDS_Iterator anItr(theShape);
443 for (; anItr.More(); anItr.Next()) {
444 SetShape(anItr.Value(),theEdgeMap,theIsVector);
448 switch (theShape.ShapeType()) {
450 TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
451 for (; anEdgeExp.More(); anEdgeExp.Next()){
452 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
453 if (!BRep_Tool::Degenerated(anEdge))
454 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
459 const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
460 if (!BRep_Tool::Degenerated(anEdge))
461 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
464 case TopAbs_VERTEX: {
468 TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
469 for(; aFaceExp.More(); aFaceExp.Next()) {
470 const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
471 myWireframeFaceSource->AddFace(aFace);
472 myShadingFaceSource->AddFace(aFace);
473 TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
474 for(; anEdgeExp.More(); anEdgeExp.Next()) {
475 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
476 if(!BRep_Tool::Degenerated(anEdge)){
477 // compute the number of faces
478 int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
480 case 0: // isolated edge
481 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
483 case 1: // edge in only one face
484 myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
486 default: // edge shared by at least two faces
487 mySharedEdgeSource->AddEdge(anEdge,theIsVector);
497 void GEOM_Actor::setDeflection(double adef) {
499 MESSAGE ( "GEOM_Actor::setDeflection" );
501 SetDeflection((float)adef,GetIsRelative());
505 // warning! must be checked!
506 // SetHighlightProperty
507 // SetWireframeProperty
508 // SetShadingProperty
510 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
513 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
515 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
519 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
522 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
525 myWireframeFaceActor->SetProperty(Prop);
528 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
531 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
533 myShadingFaceProp->DeepCopy(Prop);
537 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
540 MESSAGE ( "GEOM_Actor::Render" );
546 /* render the property */
547 if (!this->Property) {
548 // force creation of a property
550 this->Property->SetInterpolation(1);
551 this->Property->SetRepresentationToSurface();
552 this->Property->SetAmbient(0.3);
553 this->Property->SetAmbientColor(0.88,0.86,0.2);
554 this->Property->SetDiffuseColor(0.99,0.7,0.21);
555 this->Property->SetSpecularColor(0.99,0.98,0.83);
558 switch(myDisplayMode){
560 myPreHighlightProp->SetRepresentationToWireframe();
561 myHighlightProp->SetRepresentationToWireframe();
564 myPreHighlightProp->SetRepresentationToSurface();
565 myHighlightProp->SetRepresentationToSurface();
571 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
572 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
574 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
575 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
579 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
580 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
583 this->Property->Render(this, ren);
584 if (this->BackfaceProperty) {
585 this->BackfaceProperty->BackfaceRender(this, ren);
586 this->Device->SetBackfaceProperty(this->BackfaceProperty);
588 this->Device->SetProperty(this->Property);
589 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
591 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
592 static vtkFloatingPointType delta = 0.01;
593 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
594 ren->ViewToWorld(X1,Y1,Z1);
595 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
596 ren->ViewToWorld(X2,Y2,Z2);
597 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
598 this->SetScale(Z2*delta);
600 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
601 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
602 this->Device->SetUserMatrix(aMatrix);
603 this->Device->Render(ren,theMapper);
606 this->Device->Render(ren, theMapper);
609 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
612 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
618 void GEOM_Actor::ShallowCopy(vtkProp *prop)
621 MESSAGE ( "GEOM_Actor::ShallowCopy" );
623 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
626 this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
630 this->SALOME_Actor::ShallowCopy(prop);
633 const TopoDS_Shape& GEOM_Actor::getTopo() {
635 MESSAGE ( "GEOM_Actor::getTopo" );
640 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
641 int imode, bool isVector)
644 MESSAGE ( "GEOM_Actor::setInputShape" );
648 double GEOM_Actor::getDeflection()
651 MESSAGE ( "GEOM_Actor::getDeflection" );
653 return (double) GetDeflection();
657 double GEOM_Actor::isVector()
660 MESSAGE ( "GEOM_Actor::isVector" );
665 void GEOM_Actor::SubShapeOn()
668 MESSAGE ( "GEOM_Actor::SubShapeOn" );
672 void GEOM_Actor::SubShapeOff()
675 MESSAGE ( "GEOM_Actor::SubShapeOff" );
679 void GEOM_Actor::highlight(bool highlight)
682 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
684 SALOME_Actor::highlight(highlight);
687 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
690 myShadingFaceProp->SetOpacity(opa);
691 myHighlightProp->SetOpacity(opa);
692 myPreHighlightProp->SetOpacity(opa);
693 myVertexActor->GetProperty()->SetOpacity(opa);
696 vtkFloatingPointType GEOM_Actor::GetOpacity()
699 return myShadingFaceProp->GetOpacity();
702 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
705 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
706 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
707 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
708 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
709 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
712 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
715 vtkFloatingPointType aRGB[3];
716 myShadingFaceProp->GetColor(aRGB);
722 bool GEOM_Actor::IsInfinitive()
724 return ((bool)myShape.Infinite() || isOnlyVertex);
728 To map current selection to VTK representation
732 ::Highlight(bool theIsHighlight)
734 myIsSelected = theIsHighlight;
736 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
739 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
740 SetVisibility(GetVisibility());
744 To process prehighlight (called from SVTK_InteractorStyle)
748 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
749 SVTK_SelectionEvent* theSelectionEvent,
753 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
756 if ( !GetPickable() )
759 myPreHighlightActor->SetVisibility( false );
760 bool anIsPreselected = myIsPreselected;
762 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
763 bool anIsChanged = (mySelectionMode != aSelectionMode);
765 if( !theIsHighlight ) {
766 SetPreSelected( false );
768 switch(aSelectionMode){
769 case ActorSelection :
771 // cout << "=============== " << myIO->getEntry() << endl;
772 int nbio = mySelector->IObjectCount();
773 // cout << " nbio = " << nbio << endl;
775 if( !mySelector->IsSelected( myIO ) ) {
776 // printf ("!!!!!!!!!!!!!!!!\n");
777 SetPreSelected( true );
785 mySelectionMode = aSelectionMode;
786 anIsChanged |= (anIsPreselected != myIsPreselected);
788 SetVisibility(GetVisibility());
793 To process highlight (called from SVTK_InteractorStyle)
797 ::Highlight(vtkInteractorStyle *theInteractorStyle,
798 SVTK_SelectionEvent* theSelectionEvent,
801 // define the selection of object
803 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
805 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
806 SetSelected(theIsHighlight);
808 SetPreSelected(false);
814 // Copy the follower's composite 4x4 matrix into the matrix provided.
815 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
818 double Rx[3], Ry[3], Rz[3], p1[3];
819 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
823 this->GetOrientation();
824 this->Transform->Push();
825 this->Transform->PostMultiply();
826 this->Transform->Identity();
828 // apply user defined matrix last if there is one
829 if (this->UserMatrix)
831 this->Transform->Concatenate(this->UserMatrix);
834 this->Transform->Translate(-this->Origin[0],
838 this->Transform->Scale(this->Scale[0],
843 this->Transform->RotateY(this->Orientation[1]);
844 this->Transform->RotateX(this->Orientation[0]);
845 this->Transform->RotateZ(this->Orientation[2]);
851 pos = theCam->GetPosition();
852 vup = theCam->GetViewUp();
854 if (theCam->GetParallelProjection())
856 theCam->GetDirectionOfProjection(Rz);
861 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
862 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
863 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
864 for (i = 0; i < 3; i++)
866 Rz[i] = (pos[i] - this->Position[i])/distance;
870 vtkMath::Cross(vup,Rz,Rx);
871 vtkMath::Normalize(Rx);
872 vtkMath::Cross(Rz,Rx,Ry);
874 matrix->Element[0][0] = Rx[0];
875 matrix->Element[1][0] = Rx[1];
876 matrix->Element[2][0] = Rx[2];
877 matrix->Element[0][1] = Ry[0];
878 matrix->Element[1][1] = Ry[1];
879 matrix->Element[2][1] = Ry[2];
880 matrix->Element[0][2] = Rz[0];
881 matrix->Element[1][2] = Rz[1];
882 matrix->Element[2][2] = Rz[2];
884 this->Transform->Concatenate(matrix);
887 // translate to projection reference point PRP
888 // this is the camera's position blasted through
889 // the current matrix
890 p1[0] = this->Origin[0] + this->Position[0];
891 p1[1] = this->Origin[1] + this->Position[1];
892 p1[2] = this->Origin[2] + this->Position[2];
894 this->Transform->Translate(p1[0],p1[1],p1[2]);
895 this->Transform->GetMatrix(result);
898 this->Transform->Pop();