Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
1 // Copyright (C) 2007-2012  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 "GEOM_PainterPolyDataMapper.h"
41 #include "SVTK_Actor.h"
42
43 #include <OCC2VTK_Tools.h>
44
45 #include <vtkObjectFactory.h> 
46 #include <vtkRenderer.h> 
47 #include <vtkProperty.h> 
48 #include <vtkPointPicker.h>
49 #include <vtkCellPicker.h>
50  
51 #include <TopAbs_ShapeEnum.hxx>
52 #include <TopExp_Explorer.hxx>
53 #include <TopoDS.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopExp.hxx>
56  
57 #include <vtkPolyDataWriter.h> 
58  
59 #include <vtkAppendPolyData.h>  
60 #include <vtkPolyDataMapper.h>  
61 #include <vtkPolyData.h>  
62 #include <vtkTransform.h>
63 #include <vtkMatrix4x4.h>
64 #include <vtkMath.h>
65 #include <vtkCamera.h>
66
67 #include "utilities.h"
68
69 #include "SALOME_InteractiveObject.hxx"
70
71 //vtkStandardNewMacro(GEOM_Actor);
72
73 #ifndef MYDEBUG
74 //#define MYDEBUG
75 #endif
76
77 GEOM_Actor::GEOM_Actor(): 
78   isOnlyVertex(false),
79
80   myDeflection(-1),
81   myIsForced(false),
82
83   //  myDisplayMode(eWireframe), 
84   myIsSelected(false), 
85   myVectorMode(false),
86
87   myVertexActor(GEOM_DeviceActor::New(),true), 
88   myVertexSource(GEOM_VertexSource::New(),true), 
89  
90   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
91   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
92  
93   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
94   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
95  
96   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
97   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
98  
99   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
100   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
101  
102   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
103   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
104  
105   myHighlightActor(GEOM_DeviceActor::New(),true), 
106   myAppendFilter(vtkAppendPolyData::New(),true), 
107   // Use mapper as an instance of GEOM_PainterPolyDataMapper class
108   // to prevent drawing of mappers' content (due to an empty definition
109   // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
110   // !!! Presentation of GEOM_Actor is drawing only with help of actors
111   // defined in this class !!!
112   myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
113
114   myHighlightProp(vtkProperty::New()),
115   myPreHighlightProp(vtkProperty::New()),
116   myShadingFaceProp(vtkProperty::New())
117
118 #ifdef MYDEBUG
119   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
120 #endif
121
122   myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); 
123   vtkProperty* aProperty; 
124
125   myHighlightProp->SetAmbient(0.5);
126   myHighlightProp->SetDiffuse(0.3);
127   myHighlightProp->SetSpecular(0.2);
128   myHighlightProp->SetRepresentationToSurface();
129   myHighlightProp->SetAmbientColor(1, 1, 1);
130   myHighlightProp->SetDiffuseColor(1, 1, 1);
131   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
132   myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
133   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
134
135   this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
136
137   myPreHighlightProp->SetColor(0,1,1);
138   myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
139   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
140   myPreHighlightProp->SetRepresentationToWireframe();
141
142   myAppendFilter->AddInput(myVertexSource->GetOutput()); 
143   myVertexActor->SetInput(myVertexSource->GetOutput(),false); 
144   aProperty = myVertexActor->GetProperty(); 
145   aProperty->SetRepresentation(VTK_POINTS); 
146   aProperty->SetPointSize(3); 
147   aProperty->SetColor(1, 1, 0);
148  
149   myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
150   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); 
151   aProperty = myIsolatedEdgeActor->GetProperty(); 
152   aProperty->SetRepresentation(VTK_WIREFRAME); 
153   aProperty->SetColor(1, 0, 0);
154  
155   myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
156   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); 
157   aProperty = myOneFaceEdgeActor->GetProperty(); 
158   aProperty->SetRepresentation(VTK_WIREFRAME); 
159   aProperty->SetColor(0, 1, 0);
160  
161   myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); 
162   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); 
163   aProperty = mySharedEdgeActor->GetProperty(); 
164   aProperty->SetRepresentation(VTK_WIREFRAME); 
165   aProperty->SetColor(1, 1, 0);
166  
167   myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); 
168   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); 
169   aProperty = myWireframeFaceActor->GetProperty(); 
170   aProperty->SetRepresentation(VTK_WIREFRAME); 
171   aProperty->SetColor(0.5, 0.5, 0.5);
172
173   myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true); 
174
175   myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface); 
176   myShadingFaceProp->SetInterpolationToGouraud(); 
177   myShadingFaceProp->SetAmbient(1.0);
178   myShadingFaceProp->SetDiffuse(1.0);
179   myShadingFaceProp->SetSpecular(0.4);
180   myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
181   myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
182   myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
183
184   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
185
186   StoreBoundaryColors();
187
188   myNbIsos[0] = -1;
189   myNbIsos[1] = -1;
190
191   // Toggle display mode 
192   setDisplayMode(0); // WIRE FRAME
193   SetVectorMode(0);  //
194
195  
196  
197 GEOM_Actor::~GEOM_Actor() 
198
199 #ifdef MYDEBUG
200   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
201 #endif
202   myHighlightProp->Delete();
203   myPreHighlightProp->Delete();
204   myShadingFaceProp->Delete();
205
206  
207 GEOM_Actor*  
208 GEOM_Actor:: 
209 New() 
210
211   GEOM_Actor* anObject = new GEOM_Actor(); 
212   anObject->SetMapper(anObject->myPolyDataMapper.Get()); 
213   return anObject; 
214
215  
216  
217 void Write(vtkPolyData* theDataSet, const char* theFileName){ 
218   vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); 
219   MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()); 
220   aWriter->SetInput(theDataSet); 
221   aWriter->SetFileName(theFileName); 
222   //aWriter->Write(); 
223   aWriter->Delete(); 
224
225  
226 void 
227 GEOM_Actor:: 
228 SetModified() 
229
230   this->myVertexSource->Modified(); 
231   this->myIsolatedEdgeSource->Modified(); 
232   this->myOneFaceEdgeSource->Modified(); 
233   this->mySharedEdgeSource->Modified(); 
234   this->myWireframeFaceSource->Modified(); 
235   this->myShadingFaceSource->Modified(); 
236
237
238 void  
239 GEOM_Actor:: 
240 SetMapper(vtkMapper* theMapper) 
241
242   SALOME_Actor::SetMapper(theMapper); 
243
244
245 void 
246 GEOM_Actor:: 
247 AddToRender(vtkRenderer* theRenderer)
248 {
249   //SALOME_Actor::AddToRender(theRenderer);
250   
251   theRenderer->AddActor(this); 
252  
253   this->myHighlightActor->AddToRender(theRenderer); 
254   
255
256   myShadingFaceActor->AddToRender(theRenderer); 
257   myWireframeFaceActor->AddToRender(theRenderer); 
258  
259   mySharedEdgeActor->AddToRender(theRenderer); 
260   myOneFaceEdgeActor->AddToRender(theRenderer); 
261   myIsolatedEdgeActor->AddToRender(theRenderer); 
262  
263   myVertexActor->AddToRender(theRenderer); 
264 }
265  
266 void 
267 GEOM_Actor:: 
268 RemoveFromRender(vtkRenderer* theRenderer)
269 {
270   //SALOME_Actor::RemoveFromRender(theRenderer);
271
272   
273   theRenderer->RemoveActor(this);
274
275   myHighlightActor->RemoveFromRender(theRenderer); 
276   myShadingFaceActor->RemoveFromRender(theRenderer); 
277   myWireframeFaceActor->RemoveFromRender(theRenderer); 
278  
279   mySharedEdgeActor->RemoveFromRender(theRenderer); 
280   myOneFaceEdgeActor->RemoveFromRender(theRenderer); 
281   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
282  
283   myVertexActor->RemoveFromRender(theRenderer);
284
285   
286   SetSelected(false);
287   SetVisibility(false);
288 }
289
290 void  
291 GEOM_Actor:: 
292 setDisplayMode(int theMode) 
293
294 #ifdef MYDEBUG
295   MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
296 #endif
297   
298   if ( theMode == (int)eWireframe ) {
299     RestoreIsoNumbers();
300     // Restore wireframe edges colors
301     RestoreBoundaryColors();
302   }
303   else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
304     // Temporary store number of iso lines in order to recover its later 
305     // when display mode is achnged to 'Wirefame' or 'Shading'.
306     // Iso lines are not displayed in 'Shading with edges' mode.
307     StoreIsoNumbers();
308
309     // Reset number of iso lines to 0
310     ResetIsoNumbers();
311
312     if ( theMode == (int)eShadingWithEdges ) {
313       // Store wireframe edges colors
314       StoreBoundaryColors();
315
316       // Coloring edges
317       myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
318                                                    myEdgesInShadingColor[1],
319                                                    myEdgesInShadingColor[2]);
320       myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
321                                                   myEdgesInShadingColor[1],
322                                                   myEdgesInShadingColor[2]);
323       mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
324                                                  myEdgesInShadingColor[1],
325                                                  myEdgesInShadingColor[2]);
326       //SetModified();
327     } else {
328       myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
329                                                    myEdgesInWireframeColor[1],
330                                                    myEdgesInWireframeColor[2]);
331     }
332   }
333
334   VTKViewer_Actor::setDisplayMode(theMode);
335   SetVisibility(GetVisibility()); 
336
337
338 void  
339 GEOM_Actor:: 
340 SetSelected(bool theIsSelected) 
341
342 #ifdef MYDEBUG
343   MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected  );
344 #endif
345
346   myIsSelected = theIsSelected; 
347   SetVisibility(GetVisibility()); 
348
349
350 void  
351 GEOM_Actor:: 
352 SetVisibility(int theVisibility) 
353
354 #ifdef MYDEBUG
355   MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<"  myIsSelected="<< myIsSelected
356             << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
357 #endif
358
359   SALOME_Actor::SetVisibility(theVisibility);
360
361   this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
362   
363   myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected)); 
364   myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
365
366   mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
367   myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
368   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
369
370   myVertexActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);// must be added new mode points
371 }
372  
373
374 void
375 GEOM_Actor
376 ::SetNbIsos(const int theNb[2])
377 {
378   myWireframeFaceSource->SetNbIso(theNb);
379 }
380
381 void
382 GEOM_Actor
383 ::GetNbIsos(int &theNbU,int &theNbV)
384 {
385   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
386 }
387
388 void
389 GEOM_Actor
390 ::SetVectorMode(bool theMode)
391 {
392   myVectorMode = theMode;
393   myIsolatedEdgeSource->SetVectorMode(theMode);
394   myOneFaceEdgeSource->SetVectorMode(theMode);
395   mySharedEdgeSource->SetVectorMode(theMode);
396   SetModified();
397 }
398
399 bool
400 GEOM_Actor
401 ::GetVectorMode()
402 {
403   return myVectorMode;
404 }
405
406 void  
407 GEOM_Actor:: 
408 SetDeflection(float theDeflection) 
409
410   if( myDeflection == theDeflection ) 
411     return;
412     
413   myDeflection = theDeflection; 
414  
415   GEOM::MeshShape(myShape,myDeflection);
416   
417   SetModified(); 
418 }
419
420 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
421                            float theDeflection,
422                            bool theIsVector)
423 {
424   myShape = theShape;
425
426   myVertexSource->Clear();
427   myIsolatedEdgeSource->Clear();
428   myOneFaceEdgeSource->Clear();
429   mySharedEdgeSource->Clear();
430   myWireframeFaceSource->Clear();
431   myShadingFaceSource->Clear();
432
433   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
434   for (; aVertexExp.More(); aVertexExp.Next())
435   {
436      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
437      myVertexSource->AddVertex(aVertex);
438   }
439   
440   SetDeflection(theDeflection);
441
442   // look if edges are free or shared
443   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
444   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
445   
446   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
447                  myIsolatedEdgeSource.Get(),
448                  myOneFaceEdgeSource.Get(),
449                  mySharedEdgeSource.Get(),
450                  myWireframeFaceSource.Get(),
451                  myShadingFaceSource.Get());
452   isOnlyVertex =  
453     myIsolatedEdgeSource->IsEmpty() &&
454     myOneFaceEdgeSource->IsEmpty() &&
455     mySharedEdgeSource->IsEmpty() &&
456     myWireframeFaceSource->IsEmpty() &&
457     myShadingFaceSource->IsEmpty();
458
459   
460   if((bool)myShape.Infinite() || isOnlyVertex ){
461     myVertexActor->GetDeviceActor()->SetInfinitive(true);
462     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
463   }
464 }
465
466 // OLD METHODS
467 void GEOM_Actor::setDeflection(double adef) {
468 #ifdef MYDEBUG
469   MESSAGE ( "GEOM_Actor::setDeflection" );
470 #endif
471   SetDeflection((float)adef);
472 }
473
474
475 // warning! must be checked!
476 // SetHighlightProperty
477 // SetWireframeProperty
478 // SetShadingProperty
479
480 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
481 {
482 #ifdef MYDEBUG
483   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
484 #endif
485   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
486   
487 }
488
489 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
490 {
491 #ifdef MYDEBUG
492   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
493 #endif
494   // must be filled
495   myWireframeFaceActor->SetProperty(Prop);
496 }
497
498
499 vtkProperty* GEOM_Actor::GetWireframeProperty()
500 {
501   return myWireframeFaceActor->GetProperty();
502 }
503
504 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
505 {
506 #ifdef MYDEBUG
507   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
508 #endif
509   myShadingFaceProp->DeepCopy(Prop);
510 }
511
512
513 vtkProperty* GEOM_Actor::GetShadingProperty()
514 {
515   return myShadingFaceProp;
516 }
517
518
519 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
520 {
521 #ifdef MYDEBUG
522   MESSAGE ( "GEOM_Actor::Render" );
523 #endif
524
525   if(!GetVisibility())
526     return;
527
528   /* render the property */
529   if (!this->Property) {
530     // force creation of a property
531     this->GetProperty();
532     this->Property->SetInterpolation(1);
533     this->Property->SetRepresentationToSurface();
534     this->Property->SetAmbient(0.3);
535     this->Property->SetAmbientColor(0.88,0.86,0.2);
536     this->Property->SetDiffuseColor(0.99,0.7,0.21);
537     this->Property->SetSpecularColor(0.99,0.98,0.83);
538   }
539
540   switch(myDisplayMode){
541   case eWireframe://wireframe
542     myPreHighlightProp->SetRepresentationToWireframe();
543     myHighlightProp->SetRepresentationToWireframe();
544     break;
545   case eShading://shading
546   case eShadingWithEdges://shading with edges
547     myPreHighlightProp->SetRepresentationToSurface();
548     myHighlightProp->SetRepresentationToSurface();
549     myShadingFaceProp->SetRepresentationToSurface();
550     break;
551   }
552
553   if(!myIsSelected){
554     if(myIsPreselected){
555       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
556       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
557     } else {
558       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
559       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
560     }
561   }
562   else{
563     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
564     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
565   }
566
567   this->Property->Render(this, ren);
568   if (this->BackfaceProperty) {
569     this->BackfaceProperty->BackfaceRender(this, ren);
570     this->Device->SetBackfaceProperty(this->BackfaceProperty);
571   }
572   this->Device->SetProperty(this->Property);
573   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
574     if(ren){
575       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
576       static vtkFloatingPointType delta = 0.01;
577       vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
578       ren->ViewToWorld(X1,Y1,Z1);
579       vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
580       ren->ViewToWorld(X2,Y2,Z2);
581       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
582       this->SetScale(Z2*delta);
583     }
584     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
585     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
586     this->Device->SetUserMatrix(aMatrix);
587     this->Device->Render(ren,theMapper);
588     aMatrix->Delete();    
589     } else*/
590     this->Device->Render(ren, theMapper);
591 }
592
593 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
594 {
595 #ifdef MYDEBUG
596   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
597 #endif  
598 }
599
600
601
602 void GEOM_Actor::ShallowCopy(vtkProp *prop)
603 {
604 #ifdef MYDEBUG
605   MESSAGE ( "GEOM_Actor::ShallowCopy" );
606 #endif
607   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
608   if ( f != NULL )
609     {
610       this->SetShape(f->getTopo(),f->GetDeflection());
611     }
612
613   // Now do superclass
614   this->SALOME_Actor::ShallowCopy(prop);
615 }
616
617 const TopoDS_Shape& GEOM_Actor::getTopo() {
618 #ifdef MYDEBUG
619   MESSAGE ( "GEOM_Actor::getTopo" );
620 #endif
621   return myShape;
622 }
623
624 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
625                                int imode, bool isVector)
626 {
627 #ifdef MYDEBUG
628   MESSAGE ( "GEOM_Actor::setInputShape" );
629 #endif
630 }
631
632 double GEOM_Actor::getDeflection()
633 {
634 #ifdef MYDEBUG
635   MESSAGE ( "GEOM_Actor::getDeflection" );
636 #endif
637   return (double) GetDeflection();
638 }
639
640
641 double GEOM_Actor::isVector()
642 {
643 #ifdef MYDEBUG
644   MESSAGE ( "GEOM_Actor::isVector" );
645 #endif  
646   return 0;
647 }
648
649 void GEOM_Actor::SubShapeOn()
650 {
651 #ifdef MYDEBUG
652   MESSAGE ( "GEOM_Actor::SubShapeOn" );
653 #endif  
654 }
655
656 void GEOM_Actor::SubShapeOff()
657 {
658 #ifdef MYDEBUG
659   MESSAGE ( "GEOM_Actor::SubShapeOff" );
660 #endif
661 }
662
663 void GEOM_Actor::highlight(bool highlight)
664 {
665 #ifdef MYDEBUG
666   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
667 #endif
668   SALOME_Actor::highlight(highlight);  
669 }
670
671 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
672 {
673   // enk:tested OK
674   myShadingFaceProp->SetOpacity(opa);
675   myHighlightProp->SetOpacity(opa);
676   myPreHighlightProp->SetOpacity(opa);
677   myVertexActor->GetProperty()->SetOpacity(opa);
678 }
679
680 vtkFloatingPointType GEOM_Actor::GetOpacity()
681 {
682   // enk:tested OK
683   return myShadingFaceProp->GetOpacity(); 
684 }
685
686 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
687 {
688   // enk:tested OK
689   myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
690   myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
691   if ( myDisplayMode != (int)eShadingWithEdges ) {
692     myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
693     myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
694     mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
695   }
696
697   StoreBoundaryColors();
698 }
699
700 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
701 {
702   // enk:tested OK
703   vtkFloatingPointType aRGB[3];
704   myShadingFaceProp->GetColor(aRGB);
705   r = aRGB[0];
706   g = aRGB[1];
707   b = aRGB[2];
708 }
709
710 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
711 {
712   // we set material properties as back and front material
713   double aCoefnt;
714
715   // Set reflection coefficients
716   aCoefnt = theProps[0]->GetAmbient();
717   myShadingFaceProp->SetAmbient(aCoefnt);
718   myVertexActor->GetProperty()->SetAmbient(aCoefnt);
719
720   // Set diffuse coefficients
721   aCoefnt = theProps[0]->GetDiffuse();
722   myShadingFaceProp->SetDiffuse(aCoefnt);
723   myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
724   
725   // Set specular coefficients
726   aCoefnt = theProps[0]->GetSpecular();
727   myShadingFaceProp->SetSpecular(aCoefnt);
728   myVertexActor->GetProperty()->SetSpecular(aCoefnt);
729
730   double* aColor;
731
732   // Set reflection colors
733   aColor = theProps[0]->GetAmbientColor();
734   myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
735   myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
736
737   // Set diffuse colors
738   aColor = theProps[0]->GetDiffuseColor();
739   myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
740   myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
741
742   // Set specular colors
743   aColor = theProps[0]->GetSpecularColor();
744   myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
745   myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
746
747   // Set shininess
748   aCoefnt = theProps[0]->GetSpecularPower();
749   myShadingFaceProp->SetSpecularPower(aCoefnt);
750   myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
751 }
752
753 vtkProperty* GEOM_Actor::GetMaterial()
754 {
755   return myShadingFaceProp;
756 }
757
758 bool GEOM_Actor::IsInfinitive()
759 {
760   return ((bool)myShape.Infinite() || isOnlyVertex);
761 }
762
763 /*!
764   To map current selection to VTK representation
765 */
766 void
767 GEOM_Actor
768 ::Highlight(bool theIsHighlight)
769 {
770   myIsSelected = theIsHighlight;
771 #ifdef MYDEBUG
772   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
773 #endif
774
775   if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
776     if ( theIsHighlight )
777       RestoreIsoNumbers();
778     else
779       // Reset number of iso lines to 0
780       ResetIsoNumbers();
781   }
782
783   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
784   SetVisibility(GetVisibility());
785 }
786
787 /*!
788   To process prehighlight (called from SVTK_InteractorStyle)
789 */
790 bool
791 GEOM_Actor
792 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
793                SVTK_SelectionEvent* theSelectionEvent,
794                bool theIsHighlight)
795 {
796 #ifdef MYDEBUG
797   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
798 #endif
799
800   if ( !GetPickable() )
801     return false;  
802
803   if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
804     if ( theIsHighlight )
805       RestoreIsoNumbers();
806     else
807       // Reset number of iso lines to 0
808       ResetIsoNumbers();
809   }
810
811   myPreHighlightActor->SetVisibility( false );
812   bool anIsPreselected = myIsPreselected;
813   
814   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
815   bool anIsChanged = (mySelectionMode != aSelectionMode);
816
817   if( !theIsHighlight ) {
818     SetPreSelected( false );
819   }else{
820     switch(aSelectionMode){
821     case ActorSelection : 
822     {
823 //       cout << "=============== " << myIO->getEntry() << endl;
824 //       int nbio = mySelector->IObjectCount();
825 //       cout << " nbio = " << nbio << endl;
826
827       if( !mySelector->IsSelected( myIO ) ) {
828         //      printf ("!!!!!!!!!!!!!!!!\n");
829         SetPreSelected( true );
830       }
831     }
832     default:
833       break;
834     }
835   }
836
837   mySelectionMode = aSelectionMode;
838   anIsChanged |= (anIsPreselected != myIsPreselected);
839
840   SetVisibility(GetVisibility());
841   return anIsChanged;
842 }
843
844 /*!
845   To process highlight (called from SVTK_InteractorStyle)
846 */
847 bool
848 GEOM_Actor
849 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
850             SVTK_SelectionEvent* theSelectionEvent,
851             bool theIsHighlight)
852 {
853   // define the selection of object
854 #ifdef MYDEBUG
855   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
856 #endif
857   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
858   SetSelected(theIsHighlight);
859   if(theIsHighlight)
860     SetPreSelected(false);
861   
862  
863   return aRet;
864 }
865
866 // Copy the follower's composite 4x4 matrix into the matrix provided.
867 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
868 {
869   double *pos, *vup;
870   double Rx[3], Ry[3], Rz[3], p1[3];
871   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
872   int i;
873   double distance;
874   
875   this->GetOrientation();
876   this->Transform->Push();  
877   this->Transform->PostMultiply();  
878   this->Transform->Identity();
879
880   // apply user defined matrix last if there is one 
881   if (this->UserMatrix)
882     {
883     this->Transform->Concatenate(this->UserMatrix);
884     }
885
886   this->Transform->Translate(-this->Origin[0],
887                              -this->Origin[1],
888                              -this->Origin[2]);
889   // scale
890   this->Transform->Scale(this->Scale[0],
891                          this->Scale[1],
892                          this->Scale[2]);
893   
894   // rotate
895   this->Transform->RotateY(this->Orientation[1]);
896   this->Transform->RotateX(this->Orientation[0]);
897   this->Transform->RotateZ(this->Orientation[2]);
898
899   if (theCam)
900     {
901     // do the rotation
902     // first rotate y 
903     pos = theCam->GetPosition();
904     vup = theCam->GetViewUp();
905
906     if (theCam->GetParallelProjection())
907       {
908       theCam->GetDirectionOfProjection(Rz);
909       }
910     else
911       {
912       distance = sqrt(
913         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
914         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
915         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
916       for (i = 0; i < 3; i++)
917         {
918         Rz[i] = (pos[i] - this->Position[i])/distance;
919         }
920       }
921   
922     vtkMath::Cross(vup,Rz,Rx);
923     vtkMath::Normalize(Rx);
924     vtkMath::Cross(Rz,Rx,Ry);
925     
926     matrix->Element[0][0] = Rx[0];
927     matrix->Element[1][0] = Rx[1];
928     matrix->Element[2][0] = Rx[2];
929     matrix->Element[0][1] = Ry[0];
930     matrix->Element[1][1] = Ry[1];
931     matrix->Element[2][1] = Ry[2];
932     matrix->Element[0][2] = Rz[0];
933     matrix->Element[1][2] = Rz[1];
934     matrix->Element[2][2] = Rz[2];
935     
936     this->Transform->Concatenate(matrix);
937     }
938   
939   // translate to projection reference point PRP
940   // this is the camera's position blasted through
941   // the current matrix
942   p1[0] = this->Origin[0] + this->Position[0];
943   p1[1] = this->Origin[1] + this->Position[1];
944   p1[2] = this->Origin[2] + this->Position[2];
945
946   this->Transform->Translate(p1[0],p1[1],p1[2]);
947   this->Transform->GetMatrix(result);
948   
949   matrix->Delete();
950   this->Transform->Pop();  
951 }  
952
953 void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
954 {
955   myEdgesInShadingColor[0] = r;
956   myEdgesInShadingColor[1] = g;
957   myEdgesInShadingColor[2] = b;
958 }
959
960 void GEOM_Actor::StoreIsoNumbers()
961 {  
962   myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]);
963 }
964
965 void GEOM_Actor::SetIsosWidth(const int width) {
966   myWireframeFaceActor->GetProperty()->SetLineWidth(width);
967 }
968
969 int GEOM_Actor::GetIsosWidth() const {
970   return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
971 }
972
973 void GEOM_Actor::SetWidth(const int width) {
974   myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
975   myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
976   mySharedEdgeActor->GetProperty()->SetLineWidth(width);
977   myHighlightProp->SetLineWidth(width);
978   myPreHighlightProp->SetLineWidth(width+1);
979
980 }
981
982 int GEOM_Actor::GetWidth() const {
983   return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();
984 }
985     
986 void GEOM_Actor::RestoreIsoNumbers()
987 {
988   if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 )
989     // Restore number of U and (or) V iso lines
990     myWireframeFaceSource->SetNbIso(myNbIsos);
991 }
992   
993 void GEOM_Actor::ResetIsoNumbers()
994 {
995   int aNb[2] = {0, 0};
996   myWireframeFaceSource->SetNbIso(aNb);
997 }
998
999 void GEOM_Actor::StoreBoundaryColors()
1000 {
1001   myShadingFaceProp->GetColor(myEdgesInWireframeColor);
1002
1003 }
1004  
1005 void GEOM_Actor::RestoreBoundaryColors()
1006 {
1007   myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1008                                                myEdgesInWireframeColor[1],
1009                                                myEdgesInWireframeColor[2]);
1010   myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1011                                               myEdgesInWireframeColor[1],
1012                                               myEdgesInWireframeColor[2]);
1013   mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1014                                              myEdgesInWireframeColor[1],
1015                                              myEdgesInWireframeColor[2]);
1016 }