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