]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_ZLevelsOp.cxx
Salome HOME
copyrights are updated
[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_Tool.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( applyOrder() ), this, SLOT( onApply() ) );
84     connect( myDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
85   }
86   myDlg->setObjects( anObject2VisibleList );
87
88   myDlg->exec();
89 }
90
91 /**
92 */
93 bool HYDROGUI_ZLevelsOp::processApply( int& theUpdateFlags,
94                                        QString& theErrorMsg,
95                                        QStringList& theBrowseObjectsEntries )
96 {
97   bool aRes = false;
98
99   if ( myDlg ) {
100     Handle(HYDROData_Document) aDoc = doc();
101     if( !aDoc.IsNull() ) {
102       HYDROGUI_ListModel::ObjectList anObjects = myDlg->getObjects();
103       HYDROData_SequenceOfObjects anOrderedObjects;
104       foreach ( const Handle(HYDROData_Entity) anObject, anObjects ) {
105         anOrderedObjects.Append( anObject );
106       }
107
108       aDoc->SetObjectsLayerOrder( anOrderedObjects );
109
110       theUpdateFlags = UF_Model | UF_OCCViewer;
111       aRes = true;
112     }
113   }
114
115   return aRes;
116 }
117
118 /**
119 */
120 bool HYDROGUI_ZLevelsOp::isGranted() const
121 {
122   return true;
123 }
124
125 /**
126 */
127 void HYDROGUI_ZLevelsOp::processCancel()
128 {
129   // Delete the dialog
130   if ( myDlg ) {
131     delete myDlg;
132     myDlg = 0;
133   }
134 }