Salome HOME
22752: [EDF] Provide explicit feedback on what has been done by Shape Processing...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_CopyDriver.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 "GEOMImpl_CopyDriver.hxx"
24 #include "GEOMImpl_ICopy.hxx"
25 #include "GEOMImpl_Types.hxx"
26 #include "GEOM_Function.hxx"
27 #include "GEOM_Object.hxx"
28
29 #include <BRep_Tool.hxx>
30 #include <gp_Pnt.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopAbs.hxx>
35 #include <TNaming_CopyShape.hxx>
36 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
37
38 //=======================================================================
39 //function : GetID
40 //purpose  :
41 //======================================================================= 
42 const Standard_GUID& GEOMImpl_CopyDriver::GetID()
43 {
44   static Standard_GUID aCopyDriver("FF1BBB53-5D14-4df2-980B-3A668264EA16");
45   return aCopyDriver; 
46 }
47
48
49 //=======================================================================
50 //function : GEOMImpl_CopyDriver
51 //purpose  : 
52 //=======================================================================
53 GEOMImpl_CopyDriver::GEOMImpl_CopyDriver() 
54 {
55 }
56
57 //=======================================================================
58 //function : Execute
59 //purpose  :
60 //======================================================================= 
61 Standard_Integer GEOMImpl_CopyDriver::Execute(TFunction_Logbook& log) const
62 {
63   if (Label().IsNull()) return 0;    
64   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
65
66   Standard_Integer aType = aFunction->GetType();
67
68   GEOMImpl_ICopy aCI (aFunction);
69   TopoDS_Shape aCopy;
70   
71   if(aType == COPY_WITH_REF) {
72   
73     Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
74     if (aRefFunction.IsNull()) return 0;
75     TopoDS_Shape anOriginal = aRefFunction->GetValue();
76
77     TColStd_IndexedDataMapOfTransientTransient aMap;
78   
79     TNaming_CopyShape::CopyTool(anOriginal, aMap, aCopy);
80   }
81   else if(aType == COPY_WITHOUT_REF) {
82     aCopy = aFunction->GetValue();
83   }
84   
85   if (aCopy.IsNull()) return 0;
86
87   aFunction->SetValue(aCopy);
88
89   log.SetTouched(Label()); 
90
91   return 1;    
92 }
93
94 //================================================================================
95 /*!
96  * \brief Returns a name of creation operation and names and values of creation parameters
97  */
98 //================================================================================
99
100 bool GEOMImpl_CopyDriver::
101 GetCreationInformation(std::string&             theOperationName,
102                        std::vector<GEOM_Param>& theParams)
103 {
104   if (Label().IsNull()) return 0;
105   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
106
107   GEOMImpl_ICopy aCI( function );
108   Standard_Integer aType = function->GetType();
109
110
111   switch ( aType ) {
112   case COPY_WITH_REF:
113     theOperationName = "MakeCopy";
114     AddParam( theParams, "Original", aCI.GetOriginal() );
115     break;
116   case COPY_WITHOUT_REF:
117   {
118     theOperationName = "RestoreShape";
119     TDF_Label label = Label();
120     Handle(GEOM_Object) obj = GEOM_Object::GetObject(label);
121     if ( !obj.IsNull() && obj->GetType() == GEOM_FREE_BOUNDS )
122       theOperationName = "CHECK_FREE_BNDS";
123     break;
124   }
125   default:
126     return false;
127   }
128   
129   return true;
130 }
131
132 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_CopyDriver,GEOM_BaseDriver);
133
134 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_CopyDriver,GEOM_BaseDriver);