1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "GEOMImpl_CopyDriver.hxx"
24 #include "GEOMImpl_ICopy.hxx"
25 #include "GEOMImpl_ITransferData.hxx"
26 #include "GEOMImpl_Types.hxx"
27 #include "GEOM_Function.hxx"
28 #include "GEOM_Object.hxx"
29 #include "GEOMAlgo_GetInPlace.hxx"
30 #include "GEOMAlgo_GetInPlaceAPI.hxx"
32 #include <TopoDS_Shape.hxx>
34 #include <TNaming_CopyShape.hxx>
35 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <TopTools_ListOfShape.hxx>
38 #include <TopTools_MapIteratorOfMapOfShape.hxx>
42 #define DATUM_NAME_INDEX 1
43 #define DATUM_MATERIAL_INDEX 2
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_CopyDriver::GetID()
52 static Standard_GUID aCopyDriver("FF1BBB53-5D14-4df2-980B-3A668264EA16");
57 //=======================================================================
58 //function : GEOMImpl_CopyDriver
60 //=======================================================================
61 GEOMImpl_CopyDriver::GEOMImpl_CopyDriver()
65 //=======================================================================
68 //=======================================================================
69 Standard_Integer GEOMImpl_CopyDriver::Execute(LOGBOOK& log) const
71 if (Label().IsNull()) return 0;
72 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
74 Standard_Integer aType = aFunction->GetType();
76 if (aType == TRANSFER_DATA) {
77 return transferData(log);
80 GEOMImpl_ICopy aCI (aFunction);
83 if(aType == COPY_WITH_REF) {
85 Handle(GEOM_Function) aRefFunction = aCI.GetOriginal();
86 if (aRefFunction.IsNull()) return 0;
87 TopoDS_Shape anOriginal = aRefFunction->GetValue();
89 TColStd_IndexedDataMapOfTransientTransient aMap;
91 TNaming_CopyShape::CopyTool(anOriginal, aMap, aCopy);
93 else if(aType == COPY_WITHOUT_REF) {
94 aCopy = aFunction->GetValue();
97 if (aCopy.IsNull()) return 0;
99 aFunction->SetValue(aCopy);
101 #if OCC_VERSION_MAJOR < 7
102 log.SetTouched(Label());
104 log->SetTouched(Label());
110 //================================================================================
112 * \brief Returns a name of creation operation and names and values of creation parameters
114 //================================================================================
116 bool GEOMImpl_CopyDriver::
117 GetCreationInformation(std::string& theOperationName,
118 std::vector<GEOM_Param>& theParams)
120 if (Label().IsNull()) return 0;
121 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
123 GEOMImpl_ICopy aCI( function );
124 Standard_Integer aType = function->GetType();
129 theOperationName = "MakeCopy";
130 AddParam( theParams, "Original", aCI.GetOriginal() );
132 case COPY_WITHOUT_REF:
134 theOperationName = "RestoreShape";
135 TDF_Label label = Label();
136 Handle(GEOM_Object) obj = GEOM_Object::GetObject(label);
137 if ( !obj.IsNull() && obj->GetType() == GEOM_FREE_BOUNDS )
138 theOperationName = "CHECK_FREE_BNDS";
148 //================================================================================
150 * \brief Performs Transfer Data operation.
152 //================================================================================
153 Standard_Integer GEOMImpl_CopyDriver::transferData(LOGBOOK& log) const
155 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
156 GEOMImpl_ITransferData aTD (aFunction);
157 Handle(GEOM_Function) aRef1 = aTD.GetRef1();
158 Handle(GEOM_Function) aRef2 = aTD.GetRef2();
160 if (aRef1.IsNull() || aRef2.IsNull()) {
164 TopoDS_Shape aShape1 = aRef1->GetValue();
165 TopoDS_Shape aShape2 = aRef2->GetValue();
166 const int aFindMethod = aTD.GetFindMethod();
167 TopTools_IndexedDataMapOfShapeListOfShape aMapSoDest;
168 TopTools_IndexedMapOfShape anIndices1;
170 TopExp::MapShapes(aShape1, anIndices1);
172 switch (aFindMethod) {
173 case TD_GET_IN_PLACE:
174 if (!getInPlace(aShape1, anIndices1, aShape2, aMapSoDest)) {
178 case TD_GET_IN_PLACE_OLD:
179 if (!getInPlaceOld(aRef1, anIndices1, aShape2, aMapSoDest)) {
183 case TD_GET_IN_PLACE_BY_HISTORY:
184 if (!getInPlaceByHistory(aRef1, anIndices1, aShape2, aRef2, aMapSoDest)) {
192 // Perform copying names.
193 Handle(TColStd_HArray1OfExtendedString) aDatumName =
194 new TColStd_HArray1OfExtendedString(1, NB_DATUM);
195 Handle(TColStd_HArray1OfInteger) aDatumMaxVal =
196 new TColStd_HArray1OfInteger(1, NB_DATUM, 0);
197 Handle(TColStd_HArray1OfInteger) aDatumVal =
198 new TColStd_HArray1OfInteger(1, NB_DATUM, 0);
199 GEOMImpl_ITransferData aTD1(aRef1);
200 GEOMImpl_ITransferData aTD2(aRef2);
202 Standard_Integer aNbShapes = anIndices1.Extent();
203 TopTools_MapOfShape aMapFence;
205 aDatumName->SetValue(DATUM_NAME_INDEX, "GEOM_TRANSFER_DATA_NAMES");
206 aDatumName->SetValue(DATUM_MATERIAL_INDEX, "GEOM_TRANSFER_DATA_MATERIALS");
208 for (i = 1; i <= aNbShapes; ++i) {
209 const TopoDS_Shape &aSource = anIndices1.FindKey(i);
210 TCollection_AsciiString aName = aTD1.GetName(aSource);
211 TCollection_AsciiString aMaterial = aTD1.GetMaterial(aSource);
214 if (!aName.IsEmpty()) {
215 aDatumMaxVal->ChangeValue(DATUM_NAME_INDEX)++;
217 if (aMapSoDest.Contains(aSource)) {
218 aDatumVal->ChangeValue(DATUM_NAME_INDEX)++;
220 // Copy name to the list of subshapes of the second shape.
221 const TopTools_ListOfShape &aListDest =
222 aMapSoDest.FindFromKey(aSource);
223 TopTools_ListIteratorOfListOfShape anIt(aListDest);
225 for (; anIt.More(); anIt.Next()) {
226 const TopoDS_Shape &aShapeDest = anIt.Value();
228 if (aMapFence.Add(aShapeDest)) {
229 aTD2.SetName(aShapeDest, aName);
236 if (!aMaterial.IsEmpty()) {
237 aDatumMaxVal->ChangeValue(DATUM_MATERIAL_INDEX)++;
239 if (aMapSoDest.Contains(aSource)) {
240 aDatumVal->ChangeValue(DATUM_MATERIAL_INDEX)++;
242 // Copy material to the list of subshapes of the second shape.
243 const TopTools_ListOfShape &aListDest =
244 aMapSoDest.FindFromKey(aSource);
245 TopTools_ListIteratorOfListOfShape anIt(aListDest);
247 for (; anIt.More(); anIt.Next()) {
248 const TopoDS_Shape &aShapeDest = anIt.Value();
250 if (aMapFence.Add(aShapeDest)) {
251 aTD2.SetMaterial(aShapeDest, aMaterial);
259 aTD.SetDatumName(aDatumName);
260 aTD.SetDatumMaxVal(aDatumMaxVal);
261 aTD.SetDatumVal(aDatumVal);
266 //================================================================================
268 * \brief For each subshape of the source shape compute coinsident sub-shapes
269 * of the destination shape using GetInPlace method.
271 //================================================================================
273 Standard_Boolean GEOMImpl_CopyDriver::getInPlace
274 (const TopoDS_Shape &theSourceShape,
275 const TopTools_IndexedMapOfShape &theSourceIndices,
276 const TopoDS_Shape &theDestinationShape,
277 TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const
279 // Searching for the sub-shapes inside theDestinationShape shape
280 GEOMAlgo_GetInPlace aGIP;
282 if (!GEOMAlgo_GetInPlaceAPI::GetInPlace
283 (theDestinationShape, theSourceShape, aGIP)) {
284 return Standard_False;
287 const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesIn = aGIP.ShapesIn();
288 const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesOn = aGIP.ShapesOn();
291 Standard_Integer aNbShapes = theSourceIndices.Extent();
293 for (i = 1; i <= aNbShapes; ++i) {
294 const TopoDS_Shape &aSource = theSourceIndices.FindKey(i);
295 TopTools_ListOfShape aListShapes2;
296 TopTools_MapOfShape aMapShapes2;
298 for (j = 0; j < 2; ++j) {
299 const GEOMAlgo_DataMapOfShapeMapOfShape &aShapes2 =
300 j == 0 ? aShapesIn : aShapesOn;
302 if (aShapes2.IsBound(aSource)) {
303 const TopTools_MapOfShape &aMapShapesDest =
304 aShapes2.Find(aSource);
305 TopTools_MapIteratorOfMapOfShape aMapIter(aMapShapesDest);
307 for (; aMapIter.More(); aMapIter.Next()) {
308 const TopoDS_Shape &aShapeDest = aMapIter.Key();
310 if (aMapShapes2.Add(aShapeDest)) {
311 aListShapes2.Append(aShapeDest);
317 if (!aListShapes2.IsEmpty()) {
318 theMapSourceDest.Add(aSource, aListShapes2);
322 return Standard_True;
325 //================================================================================
327 * \brief For each subshape of the source shape compute coinsident sub-shapes
328 * of the destination shape using an old implementation
329 * of GetInPlace algorithm.
331 //================================================================================
333 Standard_Boolean GEOMImpl_CopyDriver::getInPlaceOld
334 (const Handle(GEOM_Function) &theSourceRef,
335 const TopTools_IndexedMapOfShape &theSourceIndices,
336 const TopoDS_Shape &theDestinationShape,
337 TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const
339 const Standard_Integer aNbShapes = theSourceIndices.Extent();
341 Standard_Integer iErr;
342 TopTools_ListOfShape aModifiedList;
343 GEOMImpl_ITransferData aTDSource(theSourceRef);
345 for (i = 1; i <= aNbShapes; ++i) {
346 const TopoDS_Shape &aSource = theSourceIndices.FindKey(i);
347 TCollection_AsciiString aName = aTDSource.GetName(aSource);
348 TCollection_AsciiString aMaterial = aTDSource.GetMaterial(aSource);
350 if (aName.IsEmpty() && aMaterial.IsEmpty()) {
354 // Call old GetInPlace.
355 iErr = GEOMAlgo_GetInPlaceAPI::GetInPlaceOld
356 (theDestinationShape, aSource, aModifiedList);
359 // Nothing is found. Skip.
365 return Standard_False;
368 theMapSourceDest.Add(aSource, aModifiedList);
371 return Standard_True;
374 //================================================================================
376 * \brief For each subshape of the source shape compute coinsident sub-shapes
377 * of the destination shape using GetInPlaceByHistory algorithm.
379 //================================================================================
381 Standard_Boolean GEOMImpl_CopyDriver::getInPlaceByHistory
382 (const Handle(GEOM_Function) &theSourceRef,
383 const TopTools_IndexedMapOfShape &theSourceIndices,
384 const TopoDS_Shape &theDestinationShape,
385 const Handle(GEOM_Function) &theDestinationRef,
386 TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const
388 const Standard_Integer aNbShapes = theSourceIndices.Extent();
390 GEOMImpl_ITransferData aTDSource(theSourceRef);
391 TopTools_IndexedMapOfShape aDestIndices;
393 TopExp::MapShapes(theDestinationShape, aDestIndices);
395 for (i = 1; i <= aNbShapes; ++i) {
396 const TopoDS_Shape &aSource = theSourceIndices.FindKey(i);
397 TCollection_AsciiString aName = aTDSource.GetName(aSource);
398 TCollection_AsciiString aMaterial = aTDSource.GetMaterial(aSource);
400 if (aName.IsEmpty() && aMaterial.IsEmpty()) {
404 // Call GetInPlaceByHistory.
405 TopTools_ListOfShape aModifiedList;
406 const Standard_Boolean isFound = GEOMAlgo_GetInPlaceAPI::GetInPlaceByHistory
407 (theDestinationRef, aDestIndices, aSource, aModifiedList);
409 if (isFound && !aModifiedList.IsEmpty()) {
410 theMapSourceDest.Add(aSource, aModifiedList);
414 return Standard_True;
417 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_CopyDriver,GEOM_BaseDriver);