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