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