1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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/
19 // File : SPlot2d_Viewer.cxx
20 // Author : Sergey RUIN
23 #include "SPlot2d_ViewModel.h"
25 #include "SPlot2d_Prs.h"
26 #include "SUIT_Session.h"
27 #include "SUIT_Application.h"
29 //#include "utilities.h"
30 #include "qapplication.h"
32 #include <qtoolbutton.h>
34 #include <qcolordialog.h>
36 #include <qwt_plot_canvas.h>
41 //ASL: Temporary commented in order to avoir dependency on SALOMEDS
43 //#include "SALOMEDSClient.hxx"
44 //#include "SALOMEDS_StudyManager.hxx"
46 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
47 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
48 // SALOMEDS::StudyManager - no linkage with SalomeApp.
50 /*static _PTR(Study) getStudyDS()
52 SALOMEDSClient_Study* aStudy = NULL;
53 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
55 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
56 // id of its underlying SALOMEDS::Study
57 SUIT_Application* app = SUIT_Session::session()->activeApplication();
58 if ( !app ) return _PTR(Study)(aStudy);
59 SUIT_Study* stud = app->activeStudy();
60 if ( !stud ) return _PTR(Study)(aStudy);
61 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
62 // get SALOMEDS_Study with this id from StudyMgr
63 return aMgr->GetStudyByID( id );
69 SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel )
70 : Plot2d_Viewer( theAutoDel )
77 SPlot2d_Viewer::~SPlot2d_Viewer()
82 Renames curve if it is found
84 void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject,
85 const QString& newName, Plot2d_ViewFrame* fr )
87 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
91 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
92 for( ; it.current(); ++it )
94 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.current() );
95 if( aCurve && aCurve->hasIO() && aCurve->getIO()->isSame( IObject ) )
97 aCurve->setVerTitle( newName );
98 int key = aViewFrame->hasCurve( aCurve );
100 aViewFrame->setCurveTitle( key, newName );
103 if( aCurve && aCurve->hasTableIO() && aCurve->getTableIO()->isSame( IObject ) )
104 aCurve->getTableIO()->setName( newName.latin1() );
106 aViewFrame->updateTitles();
110 Renames all copies of object in all view windows
111 \param IObj - object to be renamed
112 \param name - new name
114 void SPlot2d_Viewer::renameAll( const Handle(SALOME_InteractiveObject)& IObj, const QString& name )
116 SUIT_ViewManager* vm = getViewManager();
119 const QPtrVector<SUIT_ViewWindow>& wnds = vm->getViews();
120 for( int i=0; i<wnds.size(); i++ )
122 Plot2d_ViewWindow* pwnd = dynamic_cast<Plot2d_ViewWindow*>( wnds.at( i ) );
123 rename( IObj, name, pwnd->getViewFrame() );
129 Returns true if interactive object is presented in the viewer
131 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
133 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
134 if(aViewFrame == NULL) return 0;
136 if( getCurveByIO( IObject ) != NULL )
139 if(!IObject.IsNull()){
140 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
141 for(; it.current();++it) {
142 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
143 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
153 Actually this method just re-displays curves which refers to the <IObject>
155 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
157 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
158 if(aViewFrame == NULL) return;
160 SPlot2d_Curve* curve = getCurveByIO( IObject );
162 aViewFrame->updateCurve( curve, update );
166 Actually this method just erases all curves which don't refer to <IOBject>
167 and re-displays curve which is of <IObject>
169 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
171 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
172 if(aViewFrame == NULL) return;
174 Plot2d_Curve* curve = getCurveByIO( IObject );
175 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
176 for ( ; it.current(); ++it ) {
177 if(it.current() != curve)
178 aViewFrame->eraseCurve( curve );
180 aViewFrame->updateCurve( curve, false );
183 aViewFrame->Repaint();
187 Removes from the viewer the curves which refer to <IObject>
189 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
191 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
192 if(aViewFrame == NULL) return;
194 SPlot2d_Curve* curve = getCurveByIO( IObject );
196 aViewFrame->eraseCurve( curve, update );
198 // it can be table or container object selected
199 //ASL: Temporary commented in order to avoid dependency on SALOMEDS
200 /* _PTR(Study) aStudy = getStudyDS();
201 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
203 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
204 for ( ; aIter->More(); aIter->Next() ) {
205 _PTR(SObject) aChildSO = aIter->Value();
207 if ( aChildSO->ReferencedObject( refSO ) && refSO )
209 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
211 aViewFrame->eraseCurve( curve, update );
219 Removes all curves from the view
221 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
223 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
224 if(aViewFrame) aViewFrame->EraseAll();
228 Redraws Viewer contents
230 void SPlot2d_Viewer::Repaint()
232 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
233 if(aViewFrame) aViewFrame->Repaint();
239 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
241 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
242 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
243 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
249 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
251 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
252 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
253 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
257 Create presentation by entry
259 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
261 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
264 Plot2d_Prs* prs = aViewFrame->CreatePrs(entry);
266 return new SPlot2d_Prs( prs );
273 Axiluary method called before displaying of objects
275 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
277 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
281 Axiluary method called after displaying of objects
283 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
285 d->AfterDisplay( this, SALOME_Plot2dViewType() );
289 Returns true if interactive object is presented in the viewer and displayed
291 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
293 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
294 if(aViewFrame == NULL) return false;
296 SPlot2d_Curve* curve = getCurveByIO( IObject );
297 return aViewFrame->isVisible( curve );
301 Return interactive obeject if is presented in the viewer
303 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
305 Handle(SALOME_InteractiveObject) anIO;
306 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
307 if(aViewFrame == NULL) return anIO;
309 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
310 for ( ; it.current(); ++it ) {
311 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
312 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
313 anIO = aCurve->getIO();
321 Returns an active Plot2d ViewFrame or NULL
323 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
325 SUIT_ViewManager* aViewMgr = getViewManager();
327 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
329 return aViewWnd->getViewFrame();
336 \return curve by object and viewframe
337 \param theIObject - object
338 \param fr - viewframe
340 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
341 Plot2d_ViewFrame* fr )
343 if ( !theIObject.IsNull() ) {
344 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
346 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
347 for ( ; it.current(); ++it ) {
348 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
350 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
360 SLOT: called when action "Clone view" is activated
362 void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
364 if( !clonedVF || !newVF )
367 // 1) Copy all properties of view
369 newVF->copyPreferences( clonedVF );
371 // 2) Display all curves displayed in cloned view
373 QList<Plot2d_Curve> aCurves;
374 clonedVF->getCurves( aCurves );
375 QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
377 for( ; anIt!=aLast; anIt++ )
378 if( clonedVF->isVisible( *anIt ) )
379 newVF->displayCurve( *anIt, false );