]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_Actor.cxx
Salome HOME
Fixing visibility of standalone vertices when 'Vertices' display mode is switched...
[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 && (isOnlyVertex || (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   if ( theMode || isOnlyVertex ) {
402     myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
403     myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
404   } else {
405     myPreHighlightProp->SetPointSize(0);
406     myHighlightProp->SetPointSize(0);
407   }
408   SetModified();
409 }
410
411 bool
412 GEOM_Actor
413 ::GetVerticesMode()
414 {
415   return myVerticesMode;
416 }
417
418 void  
419 GEOM_Actor:: 
420 SetDeflection(float theDeflection) 
421
422   if( myDeflection == theDeflection ) 
423     return;
424     
425   myDeflection = theDeflection; 
426  
427   GEOM::MeshShape(myShape,myDeflection);
428   
429   SetModified(); 
430 }
431
432 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
433                            float theDeflection,
434                            bool theIsVector)
435 {
436   myShape = theShape;
437
438   myVertexSource->Clear();
439   myIsolatedEdgeSource->Clear();
440   myOneFaceEdgeSource->Clear();
441   mySharedEdgeSource->Clear();
442   myWireframeFaceSource->Clear();
443   myShadingFaceSource->Clear();
444
445   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
446   for (; aVertexExp.More(); aVertexExp.Next())
447   {
448      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
449      myVertexSource->AddVertex(aVertex);
450   }
451   
452   SetDeflection(theDeflection);
453
454   // look if edges are free or shared
455   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
456   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
457   
458   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
459                  myIsolatedEdgeSource.Get(),
460                  myOneFaceEdgeSource.Get(),
461                  mySharedEdgeSource.Get(),
462                  myWireframeFaceSource.Get(),
463                  myShadingFaceSource.Get());
464   isOnlyVertex =  
465     myIsolatedEdgeSource->IsEmpty() &&
466     myOneFaceEdgeSource->IsEmpty() &&
467     mySharedEdgeSource->IsEmpty() &&
468     myWireframeFaceSource->IsEmpty() &&
469     myShadingFaceSource->IsEmpty();
470
471   
472   if((bool)myShape.Infinite() || isOnlyVertex ){
473     myVertexActor->GetDeviceActor()->SetInfinitive(true);
474     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
475   }
476
477   // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
478   myAppendFilter->Update();
479 }
480
481 // OLD METHODS
482 void GEOM_Actor::setDeflection(double adef) {
483 #ifdef MYDEBUG
484   MESSAGE ( "GEOM_Actor::setDeflection" );
485 #endif
486   SetDeflection((float)adef);
487 }
488
489
490 // warning! must be checked!
491 // SetHighlightProperty
492 // SetWireframeProperty
493 // SetShadingProperty
494
495 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
496 {
497 #ifdef MYDEBUG
498   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
499 #endif
500   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
501   
502 }
503
504 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
505 {
506 #ifdef MYDEBUG
507   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
508 #endif
509   // must be filled
510   myWireframeFaceActor->SetProperty(Prop);
511 }
512
513
514 vtkProperty* GEOM_Actor::GetWireframeProperty()
515 {
516   return myWireframeFaceActor->GetProperty();
517 }
518
519 vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
520 {
521   return myIsolatedEdgeActor->GetProperty();
522 }
523
524 vtkProperty* GEOM_Actor::GetVertexProperty()
525 {
526   return myVertexActor->GetProperty();
527 }
528
529 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
530 {
531   return mySharedEdgeActor->GetProperty();
532 }
533
534 vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
535 {
536   return myOneFaceEdgeActor->GetProperty();
537 }
538
539 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
540 {
541 #ifdef MYDEBUG
542   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
543 #endif
544   myShadingFaceProp->DeepCopy(Prop);
545 }
546
547
548 vtkProperty* GEOM_Actor::GetShadingProperty()
549 {
550   return myShadingFaceProp;
551 }
552
553
554 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
555 {
556 #ifdef MYDEBUG
557   MESSAGE ( "GEOM_Actor::Render" );
558 #endif
559
560   if(!GetVisibility())
561     return;
562
563   /* render the property */
564   if (!this->Property) {
565     // force creation of a property
566     this->GetProperty();
567     this->Property->SetInterpolation(1);
568     this->Property->SetRepresentationToSurface();
569     this->Property->SetAmbient(0.3);
570     this->Property->SetAmbientColor(0.88,0.86,0.2);
571     this->Property->SetDiffuseColor(0.99,0.7,0.21);
572     this->Property->SetSpecularColor(0.99,0.98,0.83);
573   }
574
575   switch(myDisplayMode){
576   case eWireframe://wireframe
577     myPreHighlightProp->SetRepresentationToWireframe();
578     myHighlightProp->SetRepresentationToWireframe();
579     break;
580   case eShading://shading
581   case eShadingWithEdges://shading with edges
582     myPreHighlightProp->SetRepresentationToSurface();
583     myHighlightProp->SetRepresentationToSurface();
584     myShadingFaceProp->SetRepresentationToSurface();
585     myShadingBackFaceProp->SetRepresentationToSurface();
586     break;
587   }
588
589   if(!myIsSelected){
590     if(myIsPreselected){
591       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
592       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
593       myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
594     } else {
595       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
596       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
597       myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
598     }
599   }
600   else{
601     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
602     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
603     myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
604   }
605
606   this->Property->Render(this, ren);
607   if (this->BackfaceProperty) {
608     this->BackfaceProperty->BackfaceRender(this, ren);
609     this->Device->SetBackfaceProperty(this->BackfaceProperty);
610   }
611   this->Device->SetProperty(this->Property);
612   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
613     if(ren){
614       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
615       static double delta = 0.01;
616       double X1 = -1, Y1 = -1, Z1 = 0;
617       ren->ViewToWorld(X1,Y1,Z1);
618       double X2 = +1, Y2 = +1, Z2 = 0;
619       ren->ViewToWorld(X2,Y2,Z2);
620       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
621       this->SetScale(Z2*delta);
622     }
623     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
624     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
625     this->Device->SetUserMatrix(aMatrix);
626     this->Device->Render(ren,theMapper);
627     aMatrix->Delete();    
628     } else*/
629     this->Device->Render(ren, theMapper);
630 }
631
632 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
633 {
634 #ifdef MYDEBUG
635   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
636 #endif  
637 }
638
639
640
641 void GEOM_Actor::ShallowCopy(vtkProp *prop)
642 {
643 #ifdef MYDEBUG
644   MESSAGE ( "GEOM_Actor::ShallowCopy" );
645 #endif
646   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
647   if ( f != NULL )
648     {
649       this->SetShape(f->getTopo(),f->GetDeflection());
650     }
651
652   // Now do superclass
653   this->SALOME_Actor::ShallowCopy(prop);
654 }
655
656 const TopoDS_Shape& GEOM_Actor::getTopo() {
657 #ifdef MYDEBUG
658   MESSAGE ( "GEOM_Actor::getTopo" );
659 #endif
660   return myShape;
661 }
662
663 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
664                                int imode, bool isVector)
665 {
666 #ifdef MYDEBUG
667   MESSAGE ( "GEOM_Actor::setInputShape" );
668 #endif
669 }
670
671 double GEOM_Actor::getDeflection()
672 {
673 #ifdef MYDEBUG
674   MESSAGE ( "GEOM_Actor::getDeflection" );
675 #endif
676   return (double) GetDeflection();
677 }
678
679
680 double GEOM_Actor::isVector()
681 {
682 #ifdef MYDEBUG
683   MESSAGE ( "GEOM_Actor::isVector" );
684 #endif  
685   return 0;
686 }
687
688 void GEOM_Actor::SubShapeOn()
689 {
690 #ifdef MYDEBUG
691   MESSAGE ( "GEOM_Actor::SubShapeOn" );
692 #endif  
693 }
694
695 void GEOM_Actor::SubShapeOff()
696 {
697 #ifdef MYDEBUG
698   MESSAGE ( "GEOM_Actor::SubShapeOff" );
699 #endif
700 }
701
702 void GEOM_Actor::highlight(bool highlight)
703 {
704 #ifdef MYDEBUG
705   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
706 #endif
707   SALOME_Actor::highlight(highlight);  
708 }
709
710 void GEOM_Actor::SetOpacity(double opa)
711 {
712   // enk:tested OK
713   myShadingFaceProp->SetOpacity(opa);
714   myShadingBackFaceProp->SetOpacity(opa);
715   myHighlightProp->SetOpacity(opa);
716   myPreHighlightProp->SetOpacity(opa);
717   myVertexActor->GetProperty()->SetOpacity(opa);
718 }
719
720 double GEOM_Actor::GetOpacity()
721 {
722   // enk:tested OK
723   return myShadingFaceProp->GetOpacity(); 
724 }
725
726 void GEOM_Actor::SetColor(double r,double g,double b)
727 {
728   // set the same color to all sub-actors:
729   // - points
730   // - standalone edges
731   // - shared edges
732   // - free edges
733   // - shading color (front and back faces)
734   SetPointColor(r, g, b);
735   SetIsolatedEdgeColor(r, g, b);
736   SetSharedEdgeColor(r, g, b);
737   SetFreeEdgeColor(r, g, b);
738   myShadingFaceProp->SetColor(r,g,b);     // shading color
739   myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
740 }
741
742 void GEOM_Actor::GetColor(double& r,double& g,double& b)
743 {
744   double aRGB[3];
745   myShadingFaceProp->GetColor(aRGB);
746   r = aRGB[0];
747   g = aRGB[1];
748   b = aRGB[2];
749 }
750
751 /*!
752   \brief Set color of points
753   Points actor is shown in Wireframe mode only, see SetVisibility()
754 */
755 void GEOM_Actor::SetPointColor(double r,  double g,  double b)
756 {
757   myVertexActor->GetProperty()->SetColor(r, g, b);
758 }
759
760 /*!
761   \brief Set color of standalone edges, wires, vectors
762   This actor is shown in all display mode, see SetVisibility()
763   TODO: check - this color seems to be used not only for standalone edges
764 */
765 void GEOM_Actor::SetIsolatedEdgeColor(double r, double g,  double b)
766 {
767   myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
768   myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
769 }
770
771 /*!
772   \brief Set color of shared edges
773   This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
774   TODO: check - this seems to be not working currently
775 */
776 void GEOM_Actor::SetSharedEdgeColor(double r, double g, double b)
777 {
778   mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
779   if ( myDisplayMode != (int)eShadingWithEdges )
780     mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
781 }
782
783 /*!
784   \brief Set color of edges for standalone faces
785   This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
786   TODO: this color should be used not only for faces
787 */
788 void GEOM_Actor::SetFreeEdgeColor(double r, double g, double b)
789 {
790   myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
791   if ( myDisplayMode != (int)eShadingWithEdges )
792     myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
793 }
794
795 /*!
796   \brief Set color of iso-lines
797   This actor is shown only in wireframe display mode, see SetVisibility()
798 */
799 void GEOM_Actor::SetIsosColor(double r, double g, double b)
800 {
801   myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
802 }
803
804 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
805 {
806   // we set material properties as back and front material
807   int aSize = theProps.size();
808
809   if ( aSize < 1 || aSize > 2)
810     return;
811
812   // theProps[0] -- front material properties
813   // theProps[1] -- back material properties (if exist)
814
815   double aCoefnt;
816
817   // Set reflection coefficients
818   aCoefnt = theProps[0]->GetAmbient();
819   myShadingFaceProp->SetAmbient(aCoefnt);
820   myVertexActor->GetProperty()->SetAmbient(aCoefnt);
821   if ( aSize == 2 )
822     aCoefnt = theProps[1]->GetAmbient();
823   myShadingBackFaceProp->SetAmbient(aCoefnt);
824
825   // Set diffuse coefficients
826   aCoefnt = theProps[0]->GetDiffuse();
827   myShadingFaceProp->SetDiffuse(aCoefnt);
828   myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
829   if ( aSize == 2 )
830     aCoefnt = theProps[1]->GetDiffuse();
831   myShadingBackFaceProp->SetDiffuse(aCoefnt);
832   
833   // Set specular coefficients
834   aCoefnt = theProps[0]->GetSpecular();
835   myShadingFaceProp->SetSpecular(aCoefnt);
836   myVertexActor->GetProperty()->SetSpecular(aCoefnt);
837   if ( aSize == 2 )
838     aCoefnt = theProps[1]->GetSpecular();
839   myShadingBackFaceProp->SetSpecular(aCoefnt);
840
841
842   double* aColor;
843
844   // Set reflection colors
845   aColor = theProps[0]->GetAmbientColor();
846   myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
847   myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
848   if ( aSize == 2 )
849     aColor = theProps[1]->GetAmbientColor();
850   myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
851
852   // Set diffuse colors
853   aColor = theProps[0]->GetDiffuseColor();
854   myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
855   myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
856   if ( aSize == 2 )
857     aColor = theProps[1]->GetDiffuseColor();
858   myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
859
860   // Set specular colors
861   aColor = theProps[0]->GetSpecularColor();
862   myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
863   myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
864   if ( aSize == 2 )
865     aColor = theProps[1]->GetSpecularColor();
866   myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
867
868   // Set shininess
869   aCoefnt = theProps[0]->GetSpecularPower();
870   myShadingFaceProp->SetSpecularPower(aCoefnt);
871   myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
872   if ( aSize == 2 )
873     aCoefnt = theProps[1]->GetSpecularPower();
874   myShadingBackFaceProp->SetSpecularPower(aCoefnt);
875
876   // Set back face material property
877   myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
878 }
879
880 vtkProperty* GEOM_Actor::GetFrontMaterial()
881 {
882   return myShadingFaceProp;
883 }
884
885 vtkProperty* GEOM_Actor::GetBackMaterial()
886 {
887   return myShadingBackFaceProp;
888 }
889
890 bool GEOM_Actor::IsInfinitive()
891 {
892   return ((bool)myShape.Infinite() || isOnlyVertex);
893 }
894
895 /*!
896   To map current selection to VTK representation
897 */
898 void
899 GEOM_Actor
900 ::Highlight(bool theIsHighlight)
901 {
902   myIsSelected = theIsHighlight;
903 #ifdef MYDEBUG
904   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
905 #endif
906
907   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
908   SetVisibility(GetVisibility());
909 }
910
911 /*!
912   To process prehighlight (called from SVTK_InteractorStyle)
913 */
914 bool
915 GEOM_Actor
916 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
917                SVTK_SelectionEvent* theSelectionEvent,
918                bool theIsHighlight)
919 {
920 #ifdef MYDEBUG
921   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
922 #endif
923
924   if ( !GetPickable() )
925     return false;  
926
927   myPreHighlightActor->SetVisibility( false );
928   bool anIsPreselected = myIsPreselected;
929   
930   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
931   bool anIsChanged = (mySelectionMode != aSelectionMode);
932
933   if( !theIsHighlight ) {
934     SetPreSelected( false );
935   }else{
936     switch(aSelectionMode){
937     case ActorSelection : 
938     {
939 //       cout << "=============== " << myIO->getEntry() << endl;
940 //       int nbio = mySelector->IObjectCount();
941 //       cout << " nbio = " << nbio << endl;
942
943       if( !mySelector->IsSelected( myIO ) ) {
944         //      printf ("!!!!!!!!!!!!!!!!\n");
945         SetPreSelected( true );
946       }
947     }
948     default:
949       break;
950     }
951   }
952
953   mySelectionMode = aSelectionMode;
954   anIsChanged |= (anIsPreselected != myIsPreselected);
955
956   SetVisibility(GetVisibility());
957   return anIsChanged;
958 }
959
960 /*!
961   To process highlight (called from SVTK_InteractorStyle)
962 */
963 bool
964 GEOM_Actor
965 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
966             SVTK_SelectionEvent* theSelectionEvent,
967             bool theIsHighlight)
968 {
969   // define the selection of object
970 #ifdef MYDEBUG
971   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
972 #endif
973   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
974   SetSelected(theIsHighlight);
975   if(theIsHighlight)
976     SetPreSelected(false);
977   
978  
979   return aRet;
980 }
981
982 // Copy the follower's composite 4x4 matrix into the matrix provided.
983 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
984 {
985   double *pos, *vup;
986   double Rx[3], Ry[3], Rz[3], p1[3];
987   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
988   int i;
989   double distance;
990   
991   this->GetOrientation();
992   this->Transform->Push();  
993   this->Transform->PostMultiply();  
994   this->Transform->Identity();
995
996   // apply user defined matrix last if there is one 
997   if (this->UserMatrix)
998     {
999     this->Transform->Concatenate(this->UserMatrix);
1000     }
1001
1002   this->Transform->Translate(-this->Origin[0],
1003                              -this->Origin[1],
1004                              -this->Origin[2]);
1005   // scale
1006   this->Transform->Scale(this->Scale[0],
1007                          this->Scale[1],
1008                          this->Scale[2]);
1009   
1010   // rotate
1011   this->Transform->RotateY(this->Orientation[1]);
1012   this->Transform->RotateX(this->Orientation[0]);
1013   this->Transform->RotateZ(this->Orientation[2]);
1014
1015   if (theCam)
1016     {
1017     // do the rotation
1018     // first rotate y 
1019     pos = theCam->GetPosition();
1020     vup = theCam->GetViewUp();
1021
1022     if (theCam->GetParallelProjection())
1023       {
1024       theCam->GetDirectionOfProjection(Rz);
1025       }
1026     else
1027       {
1028       distance = sqrt(
1029         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
1030         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
1031         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
1032       for (i = 0; i < 3; i++)
1033         {
1034         Rz[i] = (pos[i] - this->Position[i])/distance;
1035         }
1036       }
1037   
1038     vtkMath::Cross(vup,Rz,Rx);
1039     vtkMath::Normalize(Rx);
1040     vtkMath::Cross(Rz,Rx,Ry);
1041     
1042     matrix->Element[0][0] = Rx[0];
1043     matrix->Element[1][0] = Rx[1];
1044     matrix->Element[2][0] = Rx[2];
1045     matrix->Element[0][1] = Ry[0];
1046     matrix->Element[1][1] = Ry[1];
1047     matrix->Element[2][1] = Ry[2];
1048     matrix->Element[0][2] = Rz[0];
1049     matrix->Element[1][2] = Rz[1];
1050     matrix->Element[2][2] = Rz[2];
1051     
1052     this->Transform->Concatenate(matrix);
1053     }
1054   
1055   // translate to projection reference point PRP
1056   // this is the camera's position blasted through
1057   // the current matrix
1058   p1[0] = this->Origin[0] + this->Position[0];
1059   p1[1] = this->Origin[1] + this->Position[1];
1060   p1[2] = this->Origin[2] + this->Position[2];
1061
1062   this->Transform->Translate(p1[0],p1[1],p1[2]);
1063   this->Transform->GetMatrix(result);
1064   
1065   matrix->Delete();
1066   this->Transform->Pop();  
1067 }  
1068
1069 void GEOM_Actor::SetEdgesInShadingColor(double r,double g,double b)
1070 {
1071   myEdgesInShadingColor[0] = r;
1072   myEdgesInShadingColor[1] = g;
1073   myEdgesInShadingColor[2] = b;
1074 }
1075
1076 void GEOM_Actor::SetIsosWidth(const int width) {
1077   myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1078 }
1079
1080 int GEOM_Actor::GetIsosWidth() const {
1081   return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
1082 }
1083
1084 void GEOM_Actor::SetWidth(const int width) {
1085   myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1086   myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1087   mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1088   myHighlightProp->SetLineWidth(width);
1089   myPreHighlightProp->SetLineWidth(width+1);
1090
1091 }
1092
1093 int GEOM_Actor::GetWidth() const {
1094   return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();
1095 }