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