Salome HOME
portage V8_5_0
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DuplicateOp.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_DuplicateOp.h"
20
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_UpdateFlags.h"
24
25 HYDROGUI_DuplicateOp::HYDROGUI_DuplicateOp( HYDROGUI_Module* theModule )
26 : HYDROGUI_Operation( theModule )
27 {
28   setName( tr( "DUPLICATE" ) );
29 }
30
31
32 HYDROGUI_DuplicateOp::~HYDROGUI_DuplicateOp()
33 {
34 }
35
36 void HYDROGUI_DuplicateOp::startOperation()
37 {
38   HYDROGUI_Operation::startOperation();
39
40   HYDROGUI_DataModel* aModel = module()->getDataModel();
41
42   bool anIsOk = false;
43   int aFlags = 0;
44
45   // Copy object
46   anIsOk = aModel->copy();
47   aFlags = UF_Controls;
48   if( !anIsOk )
49   {
50     abort();
51     return;
52   }
53
54   // Paste object
55   startDocOperation();
56
57   anIsOk = aModel->paste();
58   aFlags = UF_Controls | UF_Model;
59
60   if( anIsOk )
61     commitDocOperation();
62   else
63     abortDocOperation();
64
65   if( anIsOk )
66   {
67     module()->update( aFlags );
68     commit();
69   }
70   else
71     abort();
72 }