Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_ColoredPrs3d_i.hh
1 //  Copyright (C) 2007-2010  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.
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 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_ColoredPrs3d_i.hh
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #ifndef VISU_ColoredPrs3d_i_HeaderFile
29 #define VISU_ColoredPrs3d_i_HeaderFile
30
31 #include "VISU_Prs3d_i.hh"
32 #include "VISU_Result_i.hh"
33 #include "VISU_BoostSignals.h"
34 #include "SALOME_GenericObjPointer.hh"
35
36 #include <set>
37
38 class VISU_ColoredPL;
39
40 namespace VISU
41 {
42   class ColoredPrs3d_i;
43
44   //----------------------------------------------------------------------------
45   struct TMinMaxController
46   {
47     virtual
48     void
49     UpdateReference(ColoredPrs3d_i* theFromPrs3, ColoredPrs3d_i* theToPrs3d);
50
51     virtual
52     vtkFloatingPointType
53     GetComponentMin(vtkIdType theCompID);
54
55     virtual
56     vtkFloatingPointType
57     GetComponentMax(vtkIdType theCompID);
58
59     virtual
60     void
61     Register() = 0;
62
63     virtual
64     void
65     Destroy() = 0;
66   };
67   typedef SALOME::GenericObjPtr<TMinMaxController> PMinMaxController;
68
69
70   //----------------------------------------------------------------------------
71   struct TVTKMinMaxController: virtual TMinMaxController,
72                                virtual vtkObjectBase
73   {
74     virtual
75     void
76     Register()
77     {
78       vtkObjectBase::Register(NULL);
79     }
80
81     virtual
82     void
83     Destroy()
84     {
85       vtkObjectBase::Delete();
86     }
87   };
88
89
90   //----------------------------------------------------------------------------
91   PMinMaxController
92   CreateDefaultMinMaxController(VISU::ColoredPrs3d_i* theColoredPrs3d);
93   
94
95   //----------------------------------------------------------------------------
96   class VISU_I_EXPORT ColoredPrs3d_i : public virtual POA_VISU::ColoredPrs3d,
97                                        public virtual TMinMaxController,
98                                        public virtual TResultObserver,
99                                        public virtual Prs3d_i
100   {
101     ColoredPrs3d_i(const ColoredPrs3d_i&);
102
103   public:
104     //----------------------------------------------------------------------------
105     typedef Prs3d_i TSuperClass;
106     typedef VISU::ColoredPrs3d TInterface;
107
108     /*! 
109       The enumeration allow to define what mode should be used for the presentation building.
110     */
111     VISU_I_EXPORT enum EPublishInStudyMode {EPublishUnderTimeStamp, EPublishIndependently, ERegisterInCache, EDoNotPublish};
112
113     explicit
114     ColoredPrs3d_i(EPublishInStudyMode thePublishInStudyMode);
115
116     virtual
117     ~ColoredPrs3d_i();
118
119     virtual
120     void
121     Register();
122
123     virtual
124     void
125     Destroy();
126
127     virtual
128     void
129     RemoveFromStudy();
130
131     //----------------------------------------------------------------------------
132     //! To update the presentation from result in automatic way
133     virtual
134     void
135     UpdateFromResult(Result_i* theResult);
136
137     //----------------------------------------------------------------------------
138     virtual
139     void
140     SetEntity(Entity theEntity);
141
142     virtual
143     Entity
144     GetEntity();
145
146     TEntity
147     GetTEntity() const;
148
149     virtual
150     void
151     SetFieldName(const char* theFieldName);
152
153     virtual
154     char*
155     GetFieldName();
156
157     std::string
158     GetCFieldName() const;
159
160     virtual 
161     VISU::PField
162     GetField();
163
164     virtual
165     void 
166     SetTimeStampNumber(CORBA::Long theTimeStampNumber);
167
168     virtual
169     CORBA::Long
170     GetTimeStampNumber();
171
172     virtual
173     CORBA::Long
174     GetTimeStampNumberByIndex( CORBA::Long theIndex );
175
176     virtual
177     CORBA::Long
178     GetTimeStampIndexByNumber( CORBA::Long theNumber );
179
180     virtual 
181     VISU::PField
182     GetScalarField();
183
184     VISU::PMinMaxController
185     GetMinMaxController();
186
187     void
188     SetMinMaxController( const VISU::PMinMaxController& theController );
189
190     void
191     SetMinMaxController( ColoredPrs3d_i* theOrigin );
192
193     virtual
194     CORBA::Long
195     GetScalarTimeStampNumber() const;
196
197     virtual
198     VISU::ColoredPrs3dHolder::TimeStampsRange*
199     GetTimeStampsRange();
200
201     virtual 
202     CORBA::Boolean 
203     IsTimeStampFixed();
204
205     virtual
206     EPublishInStudyMode
207     GetPublishInStudyMode();
208
209     //----------------------------------------------------------------------------
210     virtual
211     CORBA::Long
212     GetScalarMode();
213
214     virtual
215     void 
216     SetScalarMode(CORBA::Long theScalarMode);
217
218     virtual
219     CORBA::Double 
220     GetMin();
221
222     virtual
223     CORBA::Double 
224     GetMax();
225
226     virtual
227     void
228     SetRange(CORBA::Double theMin, CORBA::Double theMax);
229
230     virtual
231     vtkFloatingPointType
232     GetComponentMin(vtkIdType theCompID) = 0;
233
234     virtual
235     vtkFloatingPointType
236     GetComponentMax(vtkIdType theCompID) = 0;
237
238     virtual
239     CORBA::Double 
240     GetSourceMin();
241
242     virtual
243     CORBA::Double 
244     GetSourceMax();
245
246     virtual 
247     void
248     SetSourceRange();
249
250     virtual
251     CORBA::Boolean
252     IsRangeFixed();
253
254     virtual 
255     void 
256     SetNbColors(CORBA::Long theNbColors);
257
258     virtual
259     CORBA::Long 
260     GetNbColors();
261
262     virtual
263     void
264     SetBarOrientation(VISU::ColoredPrs3dBase::Orientation theOrientation);
265
266     virtual 
267     VISU::ColoredPrs3dBase::Orientation 
268     GetBarOrientation();
269
270     virtual
271     void
272     SetPosition(CORBA::Double X, CORBA::Double Y);
273
274     virtual
275     CORBA::Double
276     GetPosX();
277
278     virtual
279     CORBA::Double
280     GetPosY();
281
282     virtual 
283     void
284     SetSize(CORBA::Double theWidth, CORBA::Double theHeight);
285     
286     virtual 
287     void
288     SetRatios(CORBA::Long theTitleSize, CORBA::Long theLabelSize, 
289               CORBA::Long theBarWidth, CORBA::Long theBarHeight);
290     
291     virtual 
292     CORBA::Double
293     GetWidth();
294
295     virtual
296     CORBA::Double
297     GetHeight();
298
299     virtual 
300     CORBA::Long
301     GetTitleSize();
302
303     virtual 
304     CORBA::Long
305     GetLabelSize();
306
307     virtual 
308     CORBA::Long
309     GetBarWidth();
310
311     virtual
312     CORBA::Long
313     GetBarHeight();
314
315     virtual 
316     void
317     SetLabels(CORBA::Long theNbLabels);
318
319     virtual
320     CORBA::Long
321     GetLabels();
322
323     virtual
324     void
325     SetLabelsFormat(const char* theFormat);
326
327     virtual
328     char* 
329     GetLabelsFormat();
330
331     virtual
332     void
333     SetTitle(const char* theTitle);
334
335     virtual
336     char* 
337     GetTitle();
338
339     std::string 
340     GetCTitle();
341
342     virtual
343     void
344     SetUnitsVisible(CORBA::Boolean isVisible);
345
346     virtual
347     CORBA::Boolean
348     IsUnitsVisible();
349
350     /*!  
351      * Set the visibility of a distribution curve.
352      * \param theIs is used to switch on/off the visibility of a distribution curve.
353      */
354     virtual void SetIsDistributionVisible(CORBA::Boolean theIs);
355     
356     //! Gets current visibility of a distribution curve
357     virtual CORBA::Boolean GetIsDistributionVisible();
358     
359     //! Gets current filtering by scalars mode
360     virtual CORBA::Boolean IsScalarFilterUsed();
361     
362     virtual void UseScalarFiltering( CORBA::Boolean theUseScalarFilter );
363
364     /*!
365      * Sets scalar range - min and max boundaries of the scalar bar.
366      * \param theMin  Min boundary of the scalar bar.
367      * \param theMax  Max boundary of the scalar bar.
368      * \param theIsFilter  if true then filter by scalars.
369      */
370     virtual
371     void
372     SetScalarFilterRange( CORBA::Double theMin, CORBA::Double theMax );
373
374     //----------------------------------------------------------------------------
375     virtual
376     CORBA::Double
377     GetScalarFilterMin();
378
379     //----------------------------------------------------------------------------
380     virtual
381     CORBA::Double
382     GetScalarFilterMax();
383
384     //----------------------------------------------------------------------------
385     //! Gets memory size actually used by the presentation (Mb).
386     virtual
387     CORBA::Float
388     GetMemorySize();
389
390     //----------------------------------------------------------------------------
391     //! Returns presentation input
392     VISU::ColoredPrs3dHolder::BasicInput*
393     GetBasicInput();
394
395     virtual
396     void
397     SetHolderEntry(const std::string& theEntry);
398
399     virtual
400     std::string
401     GetHolderEntry();
402
403     //! To keep restoring params till the explicit Restore() call
404     void
405     SaveRestoringState(SALOMEDS::SObject_ptr theSObject,
406                        const Storable::TRestoringMap& theMap);
407
408     //! To restore the presentation according to the saved state
409     void 
410     InitFromRestoringState();
411
412     //----------------------------------------------------------------------------
413     virtual 
414     const char* 
415     GetIconName() = 0;
416
417
418     //----------------------------------------------------------------------------
419     //! Sets initial source geometry
420     virtual
421     void
422     SetSourceGeometry()=0;
423
424     //! Add geometry of mesh as group. \retval the id of added group.
425     virtual 
426     void
427     AddMeshOnGroup(const char* theGroupName)=0;
428     
429     //! Removes all geometries.
430     virtual
431     void
432     RemoveAllGeom()=0;
433     
434     typedef std::string TGroupName;
435     typedef std::set<TGroupName> TGroupNames;
436     
437     const TGroupNames&
438     GetGroupNames();
439
440     //! Gets number of geometries
441     bool 
442     IsGroupsUsed();
443
444     //----------------------------------------------------------------------------
445   public:
446     /*!
447       Initlizes the in first time presentation
448     */
449     virtual
450     Storable* 
451     Create(const std::string& theMeshName, 
452            VISU::Entity theEntity,
453            const std::string& theFieldName, 
454            CORBA::Long theTimeStampNumber);
455
456     /*!
457       Retores state of the presentation
458     */
459     virtual 
460     Storable* 
461     Restore(SALOMEDS::SObject_ptr theSObject,
462             const Storable::TRestoringMap& theMap);
463
464     /*!
465       Writes persistent params of the presentation into the given stream
466     */
467     virtual 
468     void
469     ToStream(std::ostringstream& theStr);
470
471     /*!
472       Update state of the presentation according to the input.
473     */
474     virtual 
475     void
476     SameAs(const Prs3d_i* theOrigin);
477
478     virtual
479     void
480     UpdateActor(VISU_ActorBase* theActor);
481
482     virtual 
483     bool
484     IsBoldTitle();
485
486     virtual
487     void
488     SetBoldTitle(bool isBold);
489
490     virtual
491     bool
492     IsItalicTitle();
493
494     virtual
495     void
496     SetItalicTitle(bool isItalic);
497
498     virtual 
499     bool
500     IsShadowTitle();
501
502     virtual
503     void
504     SetShadowTitle(bool isShadow);
505
506     virtual 
507     int
508     GetTitFontType();
509
510     virtual
511     void
512     SetTitFontType(int theType);
513
514     virtual 
515     void
516     GetTitleColor(vtkFloatingPointType& theR, 
517                   vtkFloatingPointType& theG, 
518                   vtkFloatingPointType& theB);
519     
520     virtual
521     void
522     SetTitleColor(vtkFloatingPointType theR, 
523                   vtkFloatingPointType theG, 
524                   vtkFloatingPointType theB);    
525
526     virtual
527     bool
528     IsBoldLabel();
529
530     virtual
531     void
532     SetBoldLabel(bool isBold);
533
534     virtual
535     bool
536     IsItalicLabel();
537
538     virtual
539     void
540     SetItalicLabel(bool isItalic);
541
542     virtual
543     bool
544     IsShadowLabel();
545
546     virtual
547     void
548     SetShadowLabel(bool isShadow);
549
550     virtual 
551     int
552     GetLblFontType();
553
554     virtual
555     void
556     SetLblFontType(int theType);
557
558     virtual 
559     void
560     GetLabelColor(vtkFloatingPointType& theR, 
561                   vtkFloatingPointType& theG, 
562                   vtkFloatingPointType& theB);
563
564     virtual
565     void
566     SetLabelColor(vtkFloatingPointType theR, 
567                   vtkFloatingPointType theG, 
568                   vtkFloatingPointType theB);
569
570     virtual
571     void
572     SetMapScale(double theMapScale = 1.0);
573
574     VISU_ColoredPL* 
575     GetSpecificPL() const
576     { 
577       return myColoredPL; 
578     }
579     
580         virtual 
581     int
582     GetValLblFontType() const;
583
584     virtual 
585     void
586     SetValLblFontType( const int theType );
587
588     virtual 
589     double
590     GetValLblFontSize() const;
591
592     virtual 
593     void
594     SetValLblFontSize( const double theSize );
595
596     virtual 
597     bool
598     IsBoldValLbl() const;
599
600     virtual
601     void
602     SetBoldValLbl( const bool theVal );
603
604     virtual 
605     bool
606     IsItalicValLbl() const;
607
608     virtual
609     void
610     SetItalicValLbl( const bool theVal );
611
612     virtual 
613     bool
614     IsShadowValLbl() const;
615
616     virtual
617     void
618     SetShadowValLbl( const bool theVal );
619
620     virtual 
621     void
622     GetValLblFontColor( vtkFloatingPointType& theR, 
623                        vtkFloatingPointType& theG, 
624                        vtkFloatingPointType& theB ) const;
625
626     virtual
627     void
628     SetValLblFontColor( const vtkFloatingPointType theR, 
629                         const vtkFloatingPointType theG, 
630                         const vtkFloatingPointType theB );
631     
632     //----------------------------------------------------------------------------
633   protected:
634     /*!
635       Applyes basic input parameters to the presentation.
636       Returns true if all are right.
637     */
638     virtual 
639     bool 
640     SetInput(bool theReInit);
641
642     //! Restore input parameters if Apply function fails (redefines Prs3d::OnRestoreInput)
643     virtual 
644     void 
645     OnRestoreInput();
646
647     /*!
648       Checks whether it is possible to create presentation 
649       with the given basic parameters or not.
650     */
651     virtual 
652     bool 
653     CheckIsPossible() = 0;
654
655     /*!
656       Creates proper instance of VTK pipeline.
657     */
658     virtual
659     void 
660     CreatePipeLine(VISU_PipeLine* thePipeLine);
661
662     /*!
663       First checks whether corresponding VTK pipeline exists and create it if not. 
664       Then calls VISU_ColoredPrs3d_i::DoSetInput.
665       Returns true if during the call corresponding VTK pipeline was created,
666       false otherwise.
667     */
668     virtual 
669     bool
670     OnSetInput(bool theReInit);
671
672    /*!
673       Sets input data set according to basic input parameters -
674       Result, MeshName, Entity, FieldName and TimeStampNumber.
675     */
676     virtual 
677     void
678     DoSetInput(bool theIsInitilizePipe, bool theReInit) = 0;
679
680     /*! 
681       The enumeration allow to define what mode should be used for the presentation building.
682     */
683     enum EBuildMode {ECreateNew, ESameAs, ERestore};
684
685     /*! 
686       The enumeration allow to define what mode should be used for the presentation building.
687     */
688     Storable* 
689     Build(EBuildMode theBuildMode);
690
691     virtual
692     void
693     SetField(VISU::PField theField);
694
695     void
696     UseFixedRange(bool theUseFixedRange);
697
698     std::string 
699     GetScalarBarTitle();
700
701     //! Used in derived classes to initilize the IO for actors
702     virtual
703     std::string
704     GetActorEntry();
705
706     TGroupNames myGroupNames;
707     
708   private:
709     bool myIsRestored;
710     Storable::TRestoringMap myRestoringMap;
711     SALOMEDS::SObject_var myRestoringSObject;
712
713     // Decalare basic input parameters
714     VISU::Entity myEntity;
715     VISU::Entity myPreviousEntity;
716
717     std::string myFieldName;
718     std::string myPreviousFieldName;
719
720     CORBA::Long myTimeStampNumber;
721     CORBA::Long myPreviousTimeStampNumber;
722
723     boost::signalslib::connection myResultConnection;
724
725     bool myIsTimeStampFixed;
726
727     PField myField;
728     PMinMaxController myMinMaxController;
729     EPublishInStudyMode myPublishInStudyMode;
730
731     std::string myHolderEntry;
732
733     std::string myTitle;
734     std::string myScalarBarTitle;
735     bool        myIsUnits;
736
737     int myNumberOfLabels;
738     std::string myLabelsFormat;
739
740     VISU::ColoredPrs3dBase::Orientation myOrientation;
741     vtkFloatingPointType myPosition[2],
742                          myWidth, myHeight,
743                          myTitleSize, myLabelSize,
744                          myBarWidth, myBarHeight;
745
746     //Font management
747     bool myIsBoldTitle;
748     bool myIsItalicTitle;
749     bool myIsShadowTitle;
750     int  myTitFontType;
751     vtkFloatingPointType myTitleColor[3];
752
753     bool myIsBoldLabel;
754     bool myIsItalicLabel;
755     bool myIsShadowLabel;
756     int  myLblFontType;
757     vtkFloatingPointType myLabelColor[3];
758
759     VISU_ColoredPL* myColoredPL;
760     bool myIsFixedRange;
761
762     bool myIsDistributionVisible; // RKV
763
764     // Result labels 
765     int                  myValLblFontType;
766     double               myValLblFontSize;
767     bool                 myIsBoldValLbl;
768     bool                 myIsItalicValLbl;
769     bool                 myIsShadowValLbl;
770     vtkFloatingPointType myValLblFontColor[ 3 ];
771   };
772
773
774   //----------------------------------------------------------------------------
775   template<class TColoredPrs3d>
776   Storable* 
777   StorableEngine(SALOMEDS::SObject_ptr theSObject,
778                  const Storable::TRestoringMap& theMap,
779                  const std::string& thePrefix,
780                  CORBA::Boolean theIsMultiFile)
781   {
782     TColoredPrs3d* aColoredPrs3d = new TColoredPrs3d(ColoredPrs3d_i::EDoNotPublish);
783     return aColoredPrs3d->Restore(theSObject, theMap);
784   }
785
786
787   //----------------------------------------------------------------------------
788 }
789
790 #endif