Salome HOME
0021024: EDF 1537 GEOM: IDs of the subshapes of a shape
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  GEOM OBJECT : interactive object for Geometry entities visualization
24 //  File   : GEOM_Actor.cxx
25 //  Author : Christophe ATTANASIO
26 //  Module : GEOM
27 //  $Header$
28 //
29 /*!
30   \class GEOM_Actor GEOM_Actor.h
31   \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
32 */
33 #include "GEOM_Actor.h" 
34  
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"
41
42 #include <OCC2VTK_Tools.h>
43
44 #include <vtkObjectFactory.h> 
45 #include <vtkRenderer.h> 
46 #include <vtkProperty.h> 
47 #include <vtkPointPicker.h>
48 #include <vtkCellPicker.h>
49  
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopoDS.hxx>
53 #include <BRep_Tool.hxx>
54 #include <TopExp.hxx>
55  
56 #include <vtkPolyDataWriter.h> 
57  
58 #include <vtkAppendPolyData.h>  
59 #include <vtkPolyDataMapper.h>  
60 #include <vtkPolyData.h>  
61 #include <vtkTransform.h>
62 #include <vtkMatrix4x4.h>
63 #include <vtkMath.h>
64 #include <vtkCamera.h>
65
66 #include "utilities.h"
67
68 #include "SALOME_InteractiveObject.hxx"
69
70 //vtkStandardNewMacro(GEOM_Actor);
71
72 #ifndef MYDEBUG
73 //#define MYDEBUG
74 #endif
75
76 GEOM_Actor::GEOM_Actor(): 
77   isOnlyVertex(false),
78
79   myDeflection(-1),
80   myIsForced(false),
81
82   //  myDisplayMode(eWireframe), 
83   myIsSelected(false), 
84   myVectorMode(false),
85
86   myVertexActor(GEOM_DeviceActor::New(),true), 
87   myVertexSource(GEOM_VertexSource::New(),true), 
88  
89   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
90   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
91  
92   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
93   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
94  
95   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
96   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
97  
98   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
99   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
100  
101   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
102   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
103  
104   myHighlightActor(GEOM_DeviceActor::New(),true), 
105   myAppendFilter(vtkAppendPolyData::New(),true), 
106   myPolyDataMapper(vtkPolyDataMapper::New(),true),
107
108   myHighlightProp(vtkProperty::New()),
109   myPreHighlightProp(vtkProperty::New()),
110   myShadingFaceProp(vtkProperty::New())
111
112 #ifdef MYDEBUG
113   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
114 #endif
115
116   myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); 
117   vtkProperty* aProperty; 
118
119   myHighlightProp->SetAmbient(0.5);
120   myHighlightProp->SetDiffuse(0.3);
121   myHighlightProp->SetSpecular(0.2);
122   myHighlightProp->SetRepresentationToSurface();
123   myHighlightProp->SetAmbientColor(1, 1, 1);
124   myHighlightProp->SetDiffuseColor(1, 1, 1);
125   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
126   myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
127   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
128
129   this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
130
131   myPreHighlightProp->SetColor(0,1,1);
132   myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
133   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
134   myPreHighlightProp->SetRepresentationToWireframe();
135
136   myAppendFilter->AddInput(myVertexSource->GetOutput()); 
137   myVertexActor->SetInput(myVertexSource->GetOutput(),false); 
138   aProperty = myVertexActor->GetProperty(); 
139   aProperty->SetRepresentation(VTK_POINTS); 
140   aProperty->SetPointSize(3); 
141   aProperty->SetColor(1, 1, 0);
142  
143   myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput()); 
144   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); 
145   aProperty = myIsolatedEdgeActor->GetProperty(); 
146   aProperty->SetRepresentation(VTK_WIREFRAME); 
147   aProperty->SetColor(1, 0, 0);
148  
149   myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput()); 
150   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); 
151   aProperty = myOneFaceEdgeActor->GetProperty(); 
152   aProperty->SetRepresentation(VTK_WIREFRAME); 
153   aProperty->SetColor(0, 1, 0);
154  
155   myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); 
156   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); 
157   aProperty = mySharedEdgeActor->GetProperty(); 
158   aProperty->SetRepresentation(VTK_WIREFRAME); 
159   aProperty->SetColor(1, 1, 0);
160  
161   myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); 
162   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); 
163   aProperty = myWireframeFaceActor->GetProperty(); 
164   aProperty->SetRepresentation(VTK_WIREFRAME); 
165   aProperty->SetColor(0.5, 0.5, 0.5);
166
167   myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true); 
168
169   myShadingFaceProp->SetRepresentation(VTK_SURFACE); 
170   myShadingFaceProp->SetInterpolationToGouraud(); 
171   myShadingFaceProp->SetAmbient(1.0);
172   myShadingFaceProp->SetDiffuse(1.0);
173   myShadingFaceProp->SetSpecular(0.4);
174   myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
175   myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
176   myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
177
178   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
179
180   // Toggle display mode 
181   setDisplayMode(0); // WIRE FRAME
182   SetVectorMode(0);  //
183
184
185  
186  
187 GEOM_Actor::~GEOM_Actor() 
188
189 #ifdef MYDEBUG
190   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
191 #endif
192   myHighlightProp->Delete();
193   myPreHighlightProp->Delete();
194   myShadingFaceProp->Delete();
195
196  
197 GEOM_Actor*  
198 GEOM_Actor:: 
199 New() 
200
201   GEOM_Actor* anObject = new GEOM_Actor(); 
202   anObject->SetMapper(anObject->myPolyDataMapper.Get()); 
203   return anObject; 
204
205  
206  
207 void Write(vtkPolyData* theDataSet, const char* theFileName){ 
208   vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); 
209   MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()); 
210   aWriter->SetInput(theDataSet); 
211   aWriter->SetFileName(theFileName); 
212   //aWriter->Write(); 
213   aWriter->Delete(); 
214
215  
216 void 
217 GEOM_Actor:: 
218 SetModified() 
219
220   this->myVertexSource->Modified(); 
221   this->myIsolatedEdgeSource->Modified(); 
222   this->myOneFaceEdgeSource->Modified(); 
223   this->mySharedEdgeSource->Modified(); 
224   this->myWireframeFaceSource->Modified(); 
225   this->myShadingFaceSource->Modified(); 
226
227
228 void  
229 GEOM_Actor:: 
230 SetMapper(vtkMapper* theMapper) 
231
232   SALOME_Actor::SetMapper(theMapper); 
233
234
235 void 
236 GEOM_Actor:: 
237 AddToRender(vtkRenderer* theRenderer)
238 {
239   //SALOME_Actor::AddToRender(theRenderer);
240   
241   theRenderer->AddActor(this); 
242  
243   this->myHighlightActor->AddToRender(theRenderer); 
244   
245
246   myShadingFaceActor->AddToRender(theRenderer); 
247   myWireframeFaceActor->AddToRender(theRenderer); 
248  
249   mySharedEdgeActor->AddToRender(theRenderer); 
250   myOneFaceEdgeActor->AddToRender(theRenderer); 
251   myIsolatedEdgeActor->AddToRender(theRenderer); 
252  
253   myVertexActor->AddToRender(theRenderer); 
254 }
255  
256 void 
257 GEOM_Actor:: 
258 RemoveFromRender(vtkRenderer* theRenderer)
259 {
260   //SALOME_Actor::RemoveFromRender(theRenderer);
261
262   
263   theRenderer->RemoveActor(this);
264
265   myHighlightActor->RemoveFromRender(theRenderer); 
266   myShadingFaceActor->RemoveFromRender(theRenderer); 
267   myWireframeFaceActor->RemoveFromRender(theRenderer); 
268  
269   mySharedEdgeActor->RemoveFromRender(theRenderer); 
270   myOneFaceEdgeActor->RemoveFromRender(theRenderer); 
271   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
272  
273   myVertexActor->RemoveFromRender(theRenderer);
274
275   
276   SetSelected(false);
277   SetVisibility(false);
278 }
279
280 void  
281 GEOM_Actor:: 
282 setDisplayMode(int theMode) 
283
284 #ifdef MYDEBUG
285   MESSAGE ( "GEOM_Actor::SetDisplayMode = "<<theMode );
286 #endif
287   VTKViewer_Actor::setDisplayMode(theMode);
288   SetVisibility(GetVisibility()); 
289
290
291 void  
292 GEOM_Actor:: 
293 SetSelected(bool theIsSelected) 
294
295 #ifdef MYDEBUG
296   MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected  );
297 #endif
298
299   myIsSelected = theIsSelected; 
300   SetVisibility(GetVisibility()); 
301
302
303 void  
304 GEOM_Actor:: 
305 SetVisibility(int theVisibility) 
306
307 #ifdef MYDEBUG
308   MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<"  myIsSelected="<< myIsSelected
309             << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
310 #endif
311
312   SALOME_Actor::SetVisibility(theVisibility);
313
314   this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
315   
316   myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected)); 
317   myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
318
319   mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
320   myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
321   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
322
323   myVertexActor->SetVisibility(theVisibility && !myIsSelected);// must be added new mode points 
324 }
325  
326
327 void
328 GEOM_Actor
329 ::SetNbIsos(const int theNb[2])
330 {
331   myWireframeFaceSource->SetNbIso(theNb);
332 }
333
334 void
335 GEOM_Actor
336 ::GetNbIsos(int &theNbU,int &theNbV)
337 {
338   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
339 }
340
341 void
342 GEOM_Actor
343 ::SetVectorMode(bool theMode)
344 {
345   myVectorMode = theMode;
346   myIsolatedEdgeSource->SetVectorMode(theMode);
347   myOneFaceEdgeSource->SetVectorMode(theMode);
348   mySharedEdgeSource->SetVectorMode(theMode);
349   SetModified();
350 }
351
352 bool
353 GEOM_Actor
354 ::GetVectorMode()
355 {
356   return myVectorMode;
357 }
358
359 void  
360 GEOM_Actor:: 
361 SetDeflection(float theDeflection) 
362
363   if( myDeflection == theDeflection ) 
364     return;
365     
366   myDeflection = theDeflection; 
367  
368   GEOM::MeshShape(myShape,myDeflection);
369   
370   SetModified(); 
371 }
372
373 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
374                            float theDeflection,
375                            bool theIsVector)
376 {
377   myShape = theShape;
378
379   myVertexSource->Clear();
380   myIsolatedEdgeSource->Clear();
381   myOneFaceEdgeSource->Clear();
382   mySharedEdgeSource->Clear();
383   myWireframeFaceSource->Clear();
384   myShadingFaceSource->Clear();
385
386   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
387   for (; aVertexExp.More(); aVertexExp.Next())
388   {
389      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
390      myVertexSource->AddVertex(aVertex);
391   }
392   
393   SetDeflection(theDeflection);
394
395   // look if edges are free or shared
396   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
397   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
398   
399   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
400                  myIsolatedEdgeSource.Get(),
401                  myOneFaceEdgeSource.Get(),
402                  mySharedEdgeSource.Get(),
403                  myWireframeFaceSource.Get(),
404                  myShadingFaceSource.Get());
405   isOnlyVertex =  
406     myIsolatedEdgeSource->IsEmpty() &&
407     myOneFaceEdgeSource->IsEmpty() &&
408     mySharedEdgeSource->IsEmpty() &&
409     myWireframeFaceSource->IsEmpty() &&
410     myShadingFaceSource->IsEmpty();
411
412   
413   if((bool)myShape.Infinite() || isOnlyVertex ){
414     myVertexActor->GetDeviceActor()->SetInfinitive(true);
415     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
416   }
417 }
418
419 // OLD METHODS
420 void GEOM_Actor::setDeflection(double adef) {
421 #ifdef MYDEBUG
422   MESSAGE ( "GEOM_Actor::setDeflection" );
423 #endif
424   SetDeflection((float)adef);
425 }
426
427
428 // warning! must be checked!
429 // SetHighlightProperty
430 // SetWireframeProperty
431 // SetShadingProperty
432
433 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
434 {
435 #ifdef MYDEBUG
436   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
437 #endif
438   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
439   
440 }
441
442 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
443 {
444 #ifdef MYDEBUG
445   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
446 #endif
447   // must be filled
448   myWireframeFaceActor->SetProperty(Prop);
449 }
450
451 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
452 {
453 #ifdef MYDEBUG
454   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
455 #endif
456   myShadingFaceProp->DeepCopy(Prop);
457 }
458
459
460 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
461 {
462 #ifdef MYDEBUG
463   MESSAGE ( "GEOM_Actor::Render" );
464 #endif
465
466   if(!GetVisibility())
467     return;
468
469   /* render the property */
470   if (!this->Property) {
471     // force creation of a property
472     this->GetProperty();
473     this->Property->SetInterpolation(1);
474     this->Property->SetRepresentationToSurface();
475     this->Property->SetAmbient(0.3);
476     this->Property->SetAmbientColor(0.88,0.86,0.2);
477     this->Property->SetDiffuseColor(0.99,0.7,0.21);
478     this->Property->SetSpecularColor(0.99,0.98,0.83);
479   }
480
481   switch(myDisplayMode){
482   case 0://wireframe
483     myPreHighlightProp->SetRepresentationToWireframe();
484     myHighlightProp->SetRepresentationToWireframe();
485     break;
486   case 1://shading
487     myPreHighlightProp->SetRepresentationToSurface();
488     myHighlightProp->SetRepresentationToSurface();
489     break;
490   }
491
492   if(!myIsSelected){
493     if(myIsPreselected){
494       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
495       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
496     } else {
497       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
498       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
499     }
500   }
501   else{
502     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
503     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
504   }
505
506   this->Property->Render(this, ren);
507   if (this->BackfaceProperty) {
508     this->BackfaceProperty->BackfaceRender(this, ren);
509     this->Device->SetBackfaceProperty(this->BackfaceProperty);
510   }
511   this->Device->SetProperty(this->Property);
512   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
513     if(ren){
514       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
515       static vtkFloatingPointType delta = 0.01;
516       vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
517       ren->ViewToWorld(X1,Y1,Z1);
518       vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
519       ren->ViewToWorld(X2,Y2,Z2);
520       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
521       this->SetScale(Z2*delta);
522     }
523     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
524     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
525     this->Device->SetUserMatrix(aMatrix);
526     this->Device->Render(ren,theMapper);
527     aMatrix->Delete();    
528     } else*/
529     this->Device->Render(ren, theMapper);
530 }
531
532 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
533 {
534 #ifdef MYDEBUG
535   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
536 #endif  
537 }
538
539
540
541 void GEOM_Actor::ShallowCopy(vtkProp *prop)
542 {
543 #ifdef MYDEBUG
544   MESSAGE ( "GEOM_Actor::ShallowCopy" );
545 #endif
546   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
547   if ( f != NULL )
548     {
549       this->SetShape(f->getTopo(),f->GetDeflection());
550     }
551
552   // Now do superclass
553   this->SALOME_Actor::ShallowCopy(prop);
554 }
555
556 const TopoDS_Shape& GEOM_Actor::getTopo() {
557 #ifdef MYDEBUG
558   MESSAGE ( "GEOM_Actor::getTopo" );
559 #endif
560   return myShape;
561 }
562
563 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
564                                int imode, bool isVector)
565 {
566 #ifdef MYDEBUG
567   MESSAGE ( "GEOM_Actor::setInputShape" );
568 #endif
569 }
570
571 double GEOM_Actor::getDeflection()
572 {
573 #ifdef MYDEBUG
574   MESSAGE ( "GEOM_Actor::getDeflection" );
575 #endif
576   return (double) GetDeflection();
577 }
578
579
580 double GEOM_Actor::isVector()
581 {
582 #ifdef MYDEBUG
583   MESSAGE ( "GEOM_Actor::isVector" );
584 #endif  
585   return 0;
586 }
587
588 void GEOM_Actor::SubShapeOn()
589 {
590 #ifdef MYDEBUG
591   MESSAGE ( "GEOM_Actor::SubShapeOn" );
592 #endif  
593 }
594
595 void GEOM_Actor::SubShapeOff()
596 {
597 #ifdef MYDEBUG
598   MESSAGE ( "GEOM_Actor::SubShapeOff" );
599 #endif
600 }
601
602 void GEOM_Actor::highlight(bool highlight)
603 {
604 #ifdef MYDEBUG
605   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
606 #endif
607   SALOME_Actor::highlight(highlight);
608 }
609
610 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
611 {
612   // enk:tested OK
613   myShadingFaceProp->SetOpacity(opa);
614   myHighlightProp->SetOpacity(opa);
615   myPreHighlightProp->SetOpacity(opa);
616   myVertexActor->GetProperty()->SetOpacity(opa);
617 }
618
619 vtkFloatingPointType GEOM_Actor::GetOpacity()
620 {
621   // enk:tested OK
622   return myShadingFaceProp->GetOpacity(); 
623 }
624
625 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
626 {
627   // enk:tested OK
628   myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
629   myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
630   myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
631   myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
632   mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
633 }
634
635 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
636 {
637   // enk:tested OK
638   vtkFloatingPointType aRGB[3];
639   myShadingFaceProp->GetColor(aRGB);
640   r = aRGB[0];
641   g = aRGB[1];
642   b = aRGB[2];
643 }
644
645 bool GEOM_Actor::IsInfinitive()
646 {
647   return ((bool)myShape.Infinite() || isOnlyVertex);
648 }
649
650 /*!
651   To map current selection to VTK representation
652 */
653 void
654 GEOM_Actor
655 ::Highlight(bool theIsHighlight)
656 {
657   myIsSelected = theIsHighlight;
658 #ifdef MYDEBUG
659   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
660 #endif
661   
662   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
663   SetVisibility(GetVisibility());
664 }
665
666 /*!
667   To process prehighlight (called from SVTK_InteractorStyle)
668 */
669 bool
670 GEOM_Actor
671 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
672                SVTK_SelectionEvent* theSelectionEvent,
673                bool theIsHighlight)
674 {
675 #ifdef MYDEBUG
676   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
677 #endif
678
679   if ( !GetPickable() )
680     return false;  
681
682   myPreHighlightActor->SetVisibility( false );
683   bool anIsPreselected = myIsPreselected;
684   
685   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
686   bool anIsChanged = (mySelectionMode != aSelectionMode);
687
688   if( !theIsHighlight ) {
689     SetPreSelected( false );
690   }else{
691     switch(aSelectionMode){
692     case ActorSelection : 
693     {
694 //       cout << "=============== " << myIO->getEntry() << endl;
695 //       int nbio = mySelector->IObjectCount();
696 //       cout << " nbio = " << nbio << endl;
697
698       if( !mySelector->IsSelected( myIO ) ) {
699         //      printf ("!!!!!!!!!!!!!!!!\n");
700         SetPreSelected( true );
701       }
702     }
703     default:
704       break;
705     }
706   }
707
708   mySelectionMode = aSelectionMode;
709   anIsChanged |= (anIsPreselected != myIsPreselected);
710
711   SetVisibility(GetVisibility());
712   return anIsChanged;
713 }
714
715 /*!
716   To process highlight (called from SVTK_InteractorStyle)
717 */
718 bool
719 GEOM_Actor
720 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
721             SVTK_SelectionEvent* theSelectionEvent,
722             bool theIsHighlight)
723 {
724   // define the selection of object
725 #ifdef MYDEBUG
726   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
727 #endif
728   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
729   SetSelected(theIsHighlight);
730   if(theIsHighlight)
731     SetPreSelected(false);
732   
733  
734   return aRet;
735 }
736
737 // Copy the follower's composite 4x4 matrix into the matrix provided.
738 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
739 {
740   double *pos, *vup;
741   double Rx[3], Ry[3], Rz[3], p1[3];
742   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
743   int i;
744   double distance;
745   
746   this->GetOrientation();
747   this->Transform->Push();  
748   this->Transform->PostMultiply();  
749   this->Transform->Identity();
750
751   // apply user defined matrix last if there is one 
752   if (this->UserMatrix)
753     {
754     this->Transform->Concatenate(this->UserMatrix);
755     }
756
757   this->Transform->Translate(-this->Origin[0],
758                              -this->Origin[1],
759                              -this->Origin[2]);
760   // scale
761   this->Transform->Scale(this->Scale[0],
762                          this->Scale[1],
763                          this->Scale[2]);
764   
765   // rotate
766   this->Transform->RotateY(this->Orientation[1]);
767   this->Transform->RotateX(this->Orientation[0]);
768   this->Transform->RotateZ(this->Orientation[2]);
769
770   if (theCam)
771     {
772     // do the rotation
773     // first rotate y 
774     pos = theCam->GetPosition();
775     vup = theCam->GetViewUp();
776
777     if (theCam->GetParallelProjection())
778       {
779       theCam->GetDirectionOfProjection(Rz);
780       }
781     else
782       {
783       distance = sqrt(
784         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
785         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
786         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
787       for (i = 0; i < 3; i++)
788         {
789         Rz[i] = (pos[i] - this->Position[i])/distance;
790         }
791       }
792   
793     vtkMath::Cross(vup,Rz,Rx);
794     vtkMath::Normalize(Rx);
795     vtkMath::Cross(Rz,Rx,Ry);
796     
797     matrix->Element[0][0] = Rx[0];
798     matrix->Element[1][0] = Rx[1];
799     matrix->Element[2][0] = Rx[2];
800     matrix->Element[0][1] = Ry[0];
801     matrix->Element[1][1] = Ry[1];
802     matrix->Element[2][1] = Ry[2];
803     matrix->Element[0][2] = Rz[0];
804     matrix->Element[1][2] = Rz[1];
805     matrix->Element[2][2] = Rz[2];
806     
807     this->Transform->Concatenate(matrix);
808     }
809   
810   // translate to projection reference point PRP
811   // this is the camera's position blasted through
812   // the current matrix
813   p1[0] = this->Origin[0] + this->Position[0];
814   p1[1] = this->Origin[1] + this->Position[1];
815   p1[2] = this->Origin[2] + this->Position[2];
816
817   this->Transform->Translate(p1[0],p1[1],p1[2]);
818   this->Transform->GetMatrix(result);
819   
820   matrix->Delete();
821   this->Transform->Pop();  
822 }  
823
824