1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VISU_Tools.cxx
21 // Author : Oleg UVAROV
24 #include "VISU_Tools.h"
26 #include "VISU_Gen_i.hh"
27 #include "VISU_Table_i.hh"
28 #include "VISU_ViewManager_i.hh"
30 #include <SalomeApp_Study.h>
31 #include <SalomeApp_Application.h>
33 #include <SPlot2d_ViewModel.h>
34 #include <Plot2d_ViewFrame.h>
35 #include <Plot2d_ViewManager.h>
37 #include <SUIT_ResourceMgr.h>
39 //=============================================================================
42 //------------------------------------------------------------
43 // Internal function used by several public functions below
45 UpdateCurve(VISU::Curve_i* theCurve,
46 Plot2d_ViewFrame* thePlot,
47 SPlot2d_Curve* plotCurve,
50 if ( theDisplaying == VISU::eErase ) {
51 if ( plotCurve && thePlot )
52 thePlot->eraseCurve( plotCurve, false );
54 else if ( theDisplaying == VISU::eDisplay || theDisplaying == VISU::eDisplayOnly ) {
56 plotCurve->setHorTitle( theCurve->GetHorTitle().c_str() );
57 //plotCurve->setVerTitle( ( theCurve->GetVerTitle().c_str() ) );
58 plotCurve->setVerTitle( theCurve->GetName().c_str() );
59 plotCurve->setHorUnits( theCurve->GetHorUnits().c_str() );
60 plotCurve->setVerUnits( theCurve->GetVerUnits().c_str() );
64 int nbPoints = theCurve->GetData( xList, yList, zList );
65 if ( nbPoints > 0 && xList && yList ) {
66 plotCurve->setData( xList, yList, nbPoints, zList );
68 if ( !theCurve->IsAuto() ) {
69 plotCurve->setLine( (Plot2d::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
70 plotCurve->setMarker( (Plot2d::MarkerType)theCurve->GetMarker() );
71 SALOMEDS::Color color = theCurve->GetColor();
72 plotCurve->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
74 plotCurve->setAutoAssign( theCurve->IsAuto() );
76 thePlot->displayCurve( plotCurve, false );
79 Plot2d_Curve* crv = theCurve->CreatePresentation();
82 thePlot->displayCurve( crv, false );
83 theCurve->SetLine( (VISU::Curve::LineType)crv->getLine(), crv->getLineWidth() );
84 theCurve->SetMarker( (VISU::Curve::MarkerType)crv->getMarker());
85 SALOMEDS::Color newColor;
86 newColor.R = crv->getColor().red()/255.;
87 newColor.G = crv->getColor().green()/255.;
88 newColor.B = crv->getColor().blue()/255.;
89 theCurve->SetColor( newColor );
90 crv->setAutoAssign( theCurve->IsAuto() );
96 //------------------------------------------------------------
98 PlotTable(SalomeApp_Study* theStudy,
99 Plot2d_ViewFrame* thePlot,
100 VISU::Table_i* table,
106 if ( theDisplaying == VISU::eDisplayOnly )
108 QList<Plot2d_Curve*> clist;
109 thePlot->getCurves( clist );
110 _PTR(Study) aStudy = theStudy->studyDS();
111 _PTR(SObject) TableSO = aStudy->FindObjectID( table->GetEntry() );
113 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( TableSO );
114 for ( ; Iter->More(); Iter->Next() ) {
115 CORBA::Object_var childObject = VISU::ClientSObjectToObject( Iter->Value() );
116 if( !CORBA::is_nil( childObject ) ) {
117 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
118 if( !CORBA::is_nil( aCurve ) ) {
119 VISU::Curve_i* theCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
120 SPlot2d_Curve* plotCurve = 0;
121 SPlot2d_Curve* tmpCurve;
122 for ( int i = 0; i < clist.count(); i++ ) {
123 tmpCurve = dynamic_cast<SPlot2d_Curve*>( clist.at( i ) );
124 if (tmpCurve && tmpCurve->hasIO() &&
125 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
126 plotCurve = tmpCurve;
131 UpdateCurve( theCurve, thePlot, plotCurve, theDisplaying );
133 if ( theDisplaying == VISU::eErase && plotCurve ) {
134 clist.removeAll(plotCurve );
143 //------------------------------------------------------------
145 PlotCurve(Plot2d_ViewFrame* thePlot,
146 VISU::Curve_i* theCurve,
152 // if ( theDisplaying == VISU::eDisplayOnly )
153 // thePlot->EraseAll();
154 QList<Plot2d_Curve*> clist;
155 thePlot->getCurves( clist );
156 SPlot2d_Curve* plotCurve = 0;
157 SPlot2d_Curve* tmpCurve;
158 if(theDisplaying == VISU::eErase) {
159 // 23.06.2008 skl for IPAL17672
160 for (int i = 0; i < clist.count(); i++) {
161 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
162 if (tmpCurve && tmpCurve->hasIO() &&
163 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
164 plotCurve = tmpCurve;
165 thePlot->eraseCurve(clist.at(i));
169 UpdateCurve(theCurve, thePlot, plotCurve, theDisplaying);
172 for (int i = 0; i < clist.count(); i++) {
173 tmpCurve = dynamic_cast<SPlot2d_Curve*>(clist.at(i));
174 if (tmpCurve && tmpCurve->hasIO() &&
175 theCurve->GetEntry() == tmpCurve->getIO()->getEntry()) {
176 plotCurve = tmpCurve;
178 else if (theDisplaying == VISU::eDisplayOnly) {
179 thePlot->eraseCurve(clist.at(i));
182 UpdateCurve(theCurve, thePlot, plotCurve, theDisplaying);
188 //------------------------------------------------------------
190 PlotRemoveCurve(SalomeApp_Application* theApp,
193 QString anEntry = pCrv->GetEntry().c_str();
194 ViewManagerList pvm_list;
195 theApp->viewManagers( SPlot2d_Viewer::Type(), pvm_list );
196 ViewManagerList::Iterator pvm_it = pvm_list.begin();
197 for( ; pvm_it != pvm_list.end(); pvm_it++ ){
198 Plot2d_ViewManager* pvm = dynamic_cast<Plot2d_ViewManager*>( *pvm_it );
200 SPlot2d_Viewer* aSPlot2d = dynamic_cast<SPlot2d_Viewer*>( pvm->getViewModel() );
202 Plot2d_ViewFrame* thePlot = aSPlot2d->getActiveViewFrame();
204 QList<Plot2d_Curve*> clist;
205 thePlot->getCurves( clist );
206 for (int i = 0; i < clist.count(); i++) {
207 if(SPlot2d_Curve* plotCurve = dynamic_cast<SPlot2d_Curve*>(clist[i]))
208 if(plotCurve->hasIO() && (plotCurve->getIO()->getEntry() == anEntry))
209 thePlot->eraseCurve(clist[i]);
217 //------------------------------------------------------------
218 // Internal function used by the function below
219 SPlot2d_Curve* GetCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
220 Plot2d_ViewFrame* thePlot )
222 if ( !theIObject.IsNull() && thePlot ) {
223 CurveDict aCurves = thePlot->getCurves();
224 CurveDict::Iterator it = aCurves.begin();
225 for( ; it != aCurves.end(); ++it ) {
226 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
228 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
236 //------------------------------------------------------------
238 PlotContainer(Plot2d_ViewFrame* thePlot,
239 VISU::Container_i* container,
245 if ( theDisplaying == VISU::eDisplayOnly )
247 QList<Plot2d_Curve*> clist;
248 thePlot->getCurves( clist );
249 if ( container->GetNbCurves() > 0 ) {
250 int nbCurves = container->GetNbCurves();
251 for ( int k = 1; k <= nbCurves; k++ ) {
252 VISU::Curve_i* theCurve = container->GetCurve( k );
253 if ( theCurve && theCurve->IsValid() ) {
254 SPlot2d_Curve* plotCurve = GetCurveByIO(new SALOME_InteractiveObject(theCurve->GetEntry().c_str(), "", ""), thePlot);
256 UpdateCurve( theCurve, thePlot, plotCurve, theDisplaying );
258 if ( plotCurve && theDisplaying == VISU::eErase ) {
259 clist.removeAll( plotCurve );
265 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
268 qApp->processEvents();
271 //------------------------------------------------------------
273 CreatePlot(VISU_Gen_i* theVisuGen,
274 Plot2d_ViewFrame* thePlot,
275 _PTR(SObject) theTableSO)
277 _PTR(GenericAttribute) anAttr;
279 ( theTableSO->FindAttribute( anAttr, "AttributeTableOfInteger" ) ||
280 theTableSO->FindAttribute( anAttr, "AttributeTableOfReal" ) ) ) {
281 CORBA::Object_var aTable = VISU::ClientSObjectToObject(theTableSO);
282 CORBA::Object_var aContainer = theVisuGen->CreateContainer();
284 if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) {
285 VISU::Table_i* pTable = dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
286 VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(VISU::GetServant(aContainer).in());
288 if ( pContainer && pTable ) {
289 for ( int i = 2; i <= pTable->GetNbRows(); i++ ) {
290 CORBA::Object_var aNewCurve = theVisuGen->CreateCurve( pTable->_this(), 1, i );
291 if( !CORBA::is_nil( aNewCurve ) ) {
292 VISU::Curve_i* pCrv = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aNewCurve).in() );
294 pContainer->AddCurve( pCrv->_this() );
298 PlotContainer( thePlot, pContainer, VISU::eDisplay );
300 QString anEntry = pContainer->GetEntry().c_str();
301 _PTR(Study) aStudy = theTableSO->GetStudy();
302 _PTR(SObject) aContainerSO = aStudy->FindObjectID(anEntry.toLatin1().data());
303 _PTR(SObject) aParentSO = aContainerSO->GetFather();