Salome HOME
Start using new display order from the data model.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsOp.cxx
1 // Copyright (C) 2007-2013  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 #include "HYDROGUI_ZLevelsOp.h"
24
25 #include "HYDROGUI_ZLevelsDlg.h"
26 #include "HYDROGUI_DataModel.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
30
31 #include <HYDROData_Entity.h>
32
33 #include <LightApp_Application.h>
34 #include <LightApp_UpdateFlags.h>
35
36 #include <SUIT_Desktop.h>
37
38 /**
39   Constructor.
40   @param theModule the module
41 */
42 HYDROGUI_ZLevelsOp::HYDROGUI_ZLevelsOp( HYDROGUI_Module* theModule )
43 : HYDROGUI_Operation( theModule ),
44   myZLevelsDlg( NULL )
45 {
46   setName( tr( "SET_Z_LEVELS" ) );
47 }
48
49 /**
50   Destructor.
51 */
52 HYDROGUI_ZLevelsOp::~HYDROGUI_ZLevelsOp()
53 {
54 }
55
56 /**
57 */
58 void HYDROGUI_ZLevelsOp::startOperation()
59 {
60   HYDROGUI_Operation::startOperation();
61
62   // Prepare the list of objects
63   HYDROGUI_ZLevelsModel::Object2VisibleList anObject2VisibleList;
64
65   // get the document
66   Handle(HYDROData_Document) aDoc = doc();
67   if( !aDoc.IsNull() ) {
68     // get active OCC view id
69     size_t anActiveOCCViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
70
71     // get objects list
72     HYDROData_SequenceOfObjects aSeqOfObjects = aDoc->GetObjectsLayerOrder( Standard_True );
73     HYDROData_SequenceOfObjects::Iterator anIter( aSeqOfObjects );
74     for ( ; anIter.More(); anIter.Next() ) {
75       Handle(HYDROData_Entity) anObject = anIter.Value();
76       if ( !anObject.IsNull() ) {
77         bool isVisible = module()->isObjectVisible( anActiveOCCViewId, anObject );
78         anObject2VisibleList << HYDROGUI_ZLevelsModel::Object2Visible( anObject, isVisible );
79       }
80     }
81   }
82
83   // Show the dialog
84   myZLevelsDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop() );
85   myZLevelsDlg->setModal( true );
86   myZLevelsDlg->setObjects( anObject2VisibleList );
87
88   //TODO: check
89   connect( myZLevelsDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) );
90   connect( myZLevelsDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
91
92   myZLevelsDlg->exec();
93 }
94
95 /**
96 */
97 bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,
98                                        QString& theErrorMsg )
99 {
100   bool aRes = false;
101
102   if ( myZLevelsDlg ) {
103     Handle(HYDROData_Document) aDoc = doc();
104     if( !aDoc.IsNull() ) {
105       HYDROGUI_ZLevelsModel::ObjectList anObjects = myZLevelsDlg->getObjects();
106       HYDROData_SequenceOfObjects anOrderedObjects;
107       foreach ( const Handle(HYDROData_Entity) anObject, anObjects ) {
108         anOrderedObjects.Append( anObject );
109       }
110
111       aDoc->SetObjectsLayerOrder( anOrderedObjects );
112
113       theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
114       aRes = true;
115     }
116   }
117
118   return aRes;
119 }
120