]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_Prs3dUtils.cc
Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_I / VISU_Prs3dUtils.cc
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  VISU OBJECT : interactive object for VISU entities implementation
21 //  File   : VISU_Prs3dUtils.cc
22 //  Author : Alexey PETROV
23 //  Module : VISU
24 //
25 #include "VISU_Prs3dUtils.hh"
26 #include "VISU_Prs3d_i.hh"
27 #include "VISU_PointMap3d_i.hh"
28 #include "SalomeApp_Study.h"
29 #include "SALOME_Event.h"
30
31
32 namespace VISU
33 {
34   //----------------------------------------------------------------------------
35   TSetModified
36   ::TSetModified(VISU::PrsObject_i* thePrsObject):
37     myPrsObject(thePrsObject)
38   {
39     this->Modified();
40   }
41
42
43   //----------------------------------------------------------------------------
44   TSetModified
45   ::~TSetModified()
46   {
47     struct TEvent: public SALOME_Event
48     {
49       VISU::TSetModified* mySetModified;
50       TEvent(VISU::TSetModified* theSetModified):
51         mySetModified(theSetModified)
52       {}
53     
54       virtual
55       void
56       Execute()
57       {
58         VISU::PrsObject_i* aPrsObject = mySetModified->myPrsObject;
59         if(!aPrsObject)
60                 return;
61
62         VISU::Prs3d_i* aPrs3d;
63         VISU::PointMap3d_i* aPntMap;
64         SalomeApp_Study* aStudy;
65         unsigned long int time;
66         if( (aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aPrsObject)) && aPrs3d->GetActorEntry() != "" ) {
67                 aStudy = aPrs3d->GetGUIStudy();
68                 time = aPrs3d->GetMTime();
69         } else if ( aPntMap = dynamic_cast<VISU::PointMap3d_i*>(aPrsObject) ) {
70                 aStudy = aPntMap->GetGUIStudy();
71                 time = aPntMap->GetMTime();
72         } else 
73                 return;
74         
75         if(time > mySetModified->GetMTime()){
76           if(aStudy)
77             aStudy->Modified();
78         }
79           }
80         };
81
82     ProcessVoidEvent(new TEvent(this));
83   }
84
85   //----------------------------------------------------------------------------
86
87   std::string ToFormat( const int thePrec )
88   {
89     // "%-#6.3g"
90     char str[ 255 ];
91     sprintf( str, "%%-#.%dg", thePrec );
92     return str;
93   }
94
95   //----------------------------------------------------------------------------
96
97   int ToPrecision( const char* theFormat )
98   {
99     int N = strlen( theFormat );
100     int k = -1;
101     char str[ 255 ];
102     bool isOk = false;
103     for ( int i = 0; i < N; i++ )
104     {
105       if ( theFormat[ i ] ==  '.' )
106         k = 0;
107       else if ( theFormat[ i ] == 'g' )
108       {
109         str[ k ] = 0;
110         isOk = true;
111         break;
112       }
113       else if ( k >= 0 )
114         str[ k++ ] = theFormat[ i ];
115     }
116
117     int res = 0;
118     if ( isOk )
119       res = atoi( str );
120
121     return res;
122   }
123 };
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140