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