Salome HOME
lot 12 GUI p.1
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsOp.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ZLevelsOp.h"
20
21 #include "HYDROGUI_ZLevelsDlg.h"
22 #include "HYDROGUI_DataModel.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Tool2.h"
25 #include "HYDROGUI_UpdateFlags.h"
26 #include "HYDROGUI_ListSelector.h"
27
28 #include <HYDROData_Entity.h>
29
30 #include <LightApp_Application.h>
31 #include <LightApp_UpdateFlags.h>
32
33 #include <SUIT_Desktop.h>
34
35 /**
36   Constructor.
37   @param theModule the module
38 */
39 HYDROGUI_ZLevelsOp::HYDROGUI_ZLevelsOp( HYDROGUI_Module* theModule )
40 : HYDROGUI_Operation( theModule ),
41   myDlg( NULL )
42 {
43   setName( tr( "SET_Z_LEVELS" ) );
44 }
45
46 /**
47   Destructor.
48 */
49 HYDROGUI_ZLevelsOp::~HYDROGUI_ZLevelsOp()
50 {
51 }
52
53 /**
54 */
55 void HYDROGUI_ZLevelsOp::startOperation()
56 {
57   HYDROGUI_Operation::startOperation();
58
59   // Prepare the list of objects
60   HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
61
62   // get the document
63   Handle(HYDROData_Document) aDoc = doc();
64   if( !aDoc.IsNull() ) {
65     // get active OCC view id
66     size_t anActiveOCCViewId = HYDROGUI_Tool::GetActiveOCCViewId( module() );
67
68     // get objects list
69     HYDROData_SequenceOfObjects aSeqOfObjects = aDoc->GetObjectsLayerOrder( Standard_True );
70     HYDROData_SequenceOfObjects::Iterator anIter( aSeqOfObjects );
71     for ( ; anIter.More(); anIter.Next() ) {
72       Handle(HYDROData_Entity) anObject = anIter.Value();
73       if ( !anObject.IsNull() ) {
74         bool isVisible = module()->isObjectVisible( anActiveOCCViewId, anObject );
75         anObject2VisibleList << HYDROGUI_ListModel::Object2Visible( anObject, isVisible );
76       }
77     }
78   }
79
80   // Show the dialog
81   if ( !myDlg ) {
82     myDlg = new HYDROGUI_ZLevelsDlg( module()->getApp()->desktop(), module() );
83         connect( myDlg, SIGNAL( applyOrderAndClose() ), this, SLOT( onApplyAndClose() ) );
84     connect( myDlg, SIGNAL( applyOrder() ), this, SLOT( onApply() ) );
85     connect( myDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
86   }
87   myDlg->setObjects( anObject2VisibleList );
88
89   myDlg->exec();
90 }
91
92 /**
93 */
94 bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,
95                                        QString& theErrorMsg,
96                                        QStringList& theBrowseObjectsEntries )
97 {
98   bool aRes = false;
99
100   if ( myDlg ) {
101     Handle(HYDROData_Document) aDoc = doc();
102     if( !aDoc.IsNull() ) {
103       HYDROGUI_ListModel::ObjectList anObjects = myDlg->getObjects();
104       HYDROData_SequenceOfObjects anOrderedObjects;
105       foreach ( const Handle(HYDROData_Entity) anObject, anObjects ) {
106         anOrderedObjects.Append( anObject );
107       }
108
109       aDoc->SetObjectsLayerOrder( anOrderedObjects );
110
111       theUpdateFlags = UF_Model | UF_OCCViewer;
112       aRes = true;
113     }
114   }
115
116   return aRes;
117 }
118
119 /**
120 */
121 bool HYDROGUI_ZLevelsOp::isGranted() const
122 {
123   return true;
124 }
125
126 /**
127 */
128 void HYDROGUI_ZLevelsOp::processCancel()
129 {
130   // Delete the dialog
131   if ( myDlg ) {
132     delete myDlg;
133     myDlg = 0;
134   }
135 }
136
137 void HYDROGUI_ZLevelsOp::onApplyAndClose()
138 {
139   HYDROGUI_Operation::onApplyAndClose();
140   if ( myDlg )
141     myDlg->reject();
142 }