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/ or email : webmaster.salome@opencascade.com
19 // File : SPlot2d_Viewer.cxx
20 // Author : Sergey RUIN
23 #include "SPlot2d_ViewModel.h"
25 #include "SPlot2d_ViewWindow.h"
27 #include "SPlot2d_Prs.h"
28 #include "SUIT_Session.h"
29 #include "SUIT_Application.h"
31 //#include "utilities.h"
32 #include "qapplication.h"
34 #include <qtoolbutton.h>
36 #include <qcolordialog.h>
38 #include <qwt_plot_canvas.h>
43 //ASL: Temporary commented in order to avoir dependency on SALOMEDS
45 //#include "SALOMEDSClient.hxx"
46 //#include "SALOMEDS_StudyManager.hxx"
48 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
49 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
50 // SALOMEDS::StudyManager - no linkage with SalomeApp.
52 /*static _PTR(Study) getStudyDS()
54 SALOMEDSClient_Study* aStudy = NULL;
55 _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
57 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
58 // id of its underlying SALOMEDS::Study
59 SUIT_Application* app = SUIT_Session::session()->activeApplication();
60 if ( !app ) return _PTR(Study)(aStudy);
61 SUIT_Study* stud = app->activeStudy();
62 if ( !stud ) return _PTR(Study)(aStudy);
63 const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
64 // get SALOMEDS_Study with this id from StudyMgr
65 return aMgr->GetStudyByID( id );
71 SPlot2d_Viewer::SPlot2d_Viewer( bool theAutoDel )
72 : Plot2d_Viewer( theAutoDel )
79 SPlot2d_Viewer::~SPlot2d_Viewer()
84 Renames curve if it is found
86 void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject,
87 const QString& newName, Plot2d_ViewFrame* fr )
89 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
93 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
94 for( ; it.current(); ++it )
96 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.current() );
97 if( aCurve && aCurve->hasIO() && aCurve->getIO()->isSame( IObject ) )
99 aCurve->setVerTitle( newName );
100 int key = aViewFrame->hasCurve( aCurve );
102 aViewFrame->setCurveTitle( key, newName );
105 if( aCurve && aCurve->hasTableIO() && aCurve->getTableIO()->isSame( IObject ) )
106 aCurve->getTableIO()->setName( newName.latin1() );
108 aViewFrame->updateTitles();
112 Renames all copies of object in all view windows
113 \param IObj - object to be renamed
114 \param name - new name
116 void SPlot2d_Viewer::renameAll( const Handle(SALOME_InteractiveObject)& IObj, const QString& name )
118 SUIT_ViewManager* vm = getViewManager();
121 const QPtrVector<SUIT_ViewWindow>& wnds = vm->getViews();
122 for ( uint i = 0; i < wnds.size(); i++ )
124 Plot2d_ViewWindow* pwnd = dynamic_cast<Plot2d_ViewWindow*>( wnds.at( i ) );
125 rename( IObj, name, pwnd->getViewFrame() );
131 Returns true if interactive object is presented in the viewer
133 bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
135 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
136 if(aViewFrame == NULL) return 0;
138 if( getCurveByIO( IObject ) != NULL )
141 if(!IObject.IsNull()){
142 QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
143 for(; it.current();++it) {
144 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
145 if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
155 Actually this method just re-displays curves which refers to the <IObject>
157 void SPlot2d_Viewer::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
159 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
160 if(aViewFrame == NULL) return;
162 SPlot2d_Curve* curve = getCurveByIO( IObject );
164 aViewFrame->updateCurve( curve, update );
168 Actually this method just erases all curves which don't refer to <IOBject>
169 and re-displays curve which is of <IObject>
171 void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
173 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
174 if(aViewFrame == NULL) return;
176 Plot2d_Curve* curve = getCurveByIO( IObject );
177 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
178 for ( ; it.current(); ++it ) {
179 if(it.current() != curve)
180 aViewFrame->eraseCurve( curve );
182 aViewFrame->updateCurve( curve, false );
185 aViewFrame->Repaint();
189 Removes from the viewer the curves which refer to <IObject>
191 void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
193 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
194 if(aViewFrame == NULL) return;
196 SPlot2d_Curve* curve = getCurveByIO( IObject );
198 aViewFrame->eraseCurve( curve, update );
200 // it can be table or container object selected
201 //ASL: Temporary commented in order to avoid dependency on SALOMEDS
202 /* _PTR(Study) aStudy = getStudyDS();
203 _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
205 _PTR(ChildIterator) aIter = aStudy->NewChildIterator( aSO );
206 for ( ; aIter->More(); aIter->Next() ) {
207 _PTR(SObject) aChildSO = aIter->Value();
209 if ( aChildSO->ReferencedObject( refSO ) && refSO )
211 curve = getCurveByIO( new SALOME_InteractiveObject( aChildSO->GetID().c_str(), "") );
213 aViewFrame->eraseCurve( curve, update );
221 Removes all curves from the view
223 void SPlot2d_Viewer::EraseAll(const bool /*forced*/)
225 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
226 if(aViewFrame) aViewFrame->EraseAll();
230 Redraws Viewer contents
232 void SPlot2d_Viewer::Repaint()
234 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
235 if(aViewFrame) aViewFrame->Repaint();
241 void SPlot2d_Viewer::Display( const SALOME_Prs2d* prs )
243 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
244 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
245 if(aViewFrame && aPrs) aViewFrame->Display(aPrs);
251 void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
253 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
254 Plot2d_Prs* aPrs = dynamic_cast<Plot2d_Prs*>(const_cast<SALOME_Prs2d*>(prs));
255 if(aViewFrame && aPrs) aViewFrame->Erase(aPrs);
259 Create presentation by entry
261 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
263 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
266 Plot2d_Prs* prs = aViewFrame->CreatePrs(entry);
268 return new SPlot2d_Prs( prs );
275 Axiluary method called before displaying of objects
277 void SPlot2d_Viewer::BeforeDisplay( SALOME_Displayer* d )
279 d->BeforeDisplay( this, SALOME_Plot2dViewType() );
283 Axiluary method called after displaying of objects
285 void SPlot2d_Viewer::AfterDisplay( SALOME_Displayer* d )
287 d->AfterDisplay( this, SALOME_Plot2dViewType() );
291 Returns true if interactive object is presented in the viewer and displayed
293 bool SPlot2d_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
295 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
296 if(aViewFrame == NULL) return false;
298 SPlot2d_Curve* curve = getCurveByIO( IObject );
299 return aViewFrame->isVisible( curve );
303 Return interactive obeject if is presented in the viewer
305 Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry )
307 Handle(SALOME_InteractiveObject) anIO;
308 Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
309 if(aViewFrame == NULL) return anIO;
311 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
312 for ( ; it.current(); ++it ) {
313 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
314 if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
315 anIO = aCurve->getIO();
323 Returns an active Plot2d ViewFrame or NULL
325 Plot2d_ViewFrame* SPlot2d_Viewer::getActiveViewFrame()
327 SUIT_ViewManager* aViewMgr = getViewManager();
329 Plot2d_ViewWindow* aViewWnd = dynamic_cast<Plot2d_ViewWindow*>(aViewMgr->getActiveView());
331 return aViewWnd->getViewFrame();
338 \return curve by object and viewframe
339 \param theIObject - object
340 \param fr - viewframe
342 SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject,
343 Plot2d_ViewFrame* fr )
345 if ( !theIObject.IsNull() ) {
346 Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
348 QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
349 for ( ; it.current(); ++it ) {
350 SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current());
352 if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
362 SLOT: called when action "Clone view" is activated
364 void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
366 if( !clonedVF || !newVF )
369 // 1) Copy all properties of view
371 newVF->copyPreferences( clonedVF );
373 // 2) Display all curves displayed in cloned view
375 QList<Plot2d_Curve> aCurves;
376 clonedVF->getCurves( aCurves );
377 QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
379 for( ; anIt!=aLast; anIt++ )
380 if( clonedVF->isVisible( *anIt ) )
381 newVF->displayCurve( *anIt, false );
386 create SPlot2d_ViewWindow
388 SUIT_ViewWindow* SPlot2d_Viewer::createView( SUIT_Desktop* theDesktop )
390 SPlot2d_ViewWindow* aPlot2dView = new SPlot2d_ViewWindow(theDesktop, this);
392 aPlot2dView->getViewFrame()->Display(getPrs());