]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Implement data transfering
authorskv <skv@opencascade.com>
Wed, 10 Dec 2014 08:04:29 +0000 (11:04 +0300)
committerskv <skv@opencascade.com>
Wed, 10 Dec 2014 08:04:29 +0000 (11:04 +0300)
src/GEOMGUI/GEOM_msg_en.ts
src/GEOMImpl/CMakeLists.txt
src/GEOMImpl/GEOMImpl_CopyDriver.cxx
src/GEOMImpl/GEOMImpl_CopyDriver.hxx
src/GEOMImpl/GEOMImpl_IInsertOperations.cxx
src/GEOMImpl/GEOMImpl_ITransferData.cxx [new file with mode: 0644]
src/GEOMImpl/GEOMImpl_ITransferData.hxx
src/OperationGUI/OperationGUI_TransferDataDlg.cxx

index 7b2e3b8f9329981bd978c8b5483e0b97736b6887..43b4de74d2dca2bda46cf0b8f2c0d75968b64bee 100644 (file)
@@ -7198,5 +7198,21 @@ Do you want to create new material?</translation>
         <source>GEOM_TRANSFER_DATA_INFO</source>
         <translation>Transfer Data: Information</translation>
     </message>
+    <message>
+        <source>GEOM_TRANSFER_DATA_NOT_COPIED</source>
+        <translation>There is nothing to be copied.</translation>
+    </message>
+    <message>
+        <source>GEOM_TRANSFER_DATA_COPIED</source>
+        <translation>The following data is copied:</translation>
+    </message>
+    <message>
+        <source>GEOM_TRANSFER_DATA_NAMES</source>
+        <translation>Names: %1 of %2</translation>
+    </message>
+    <message>
+        <source>GEOM_TRANSFER_DATA_MATERIALS</source>
+        <translation>Materials: %1 of %2</translation>
+    </message>
 </context>
 </TS>
index 3828848e5d088bf5fa083afd8930f09f06348330..f9a063d5d719726e6691a0978f05a176be74261d 100755 (executable)
@@ -197,6 +197,7 @@ SET(GEOMImpl_SOURCES
   GEOMImpl_IFieldOperations.cxx
   GEOMImpl_IBaseIEOperations.cxx
   GEOMImpl_IPolyline2D.cxx
+  GEOMImpl_ITransferData.cxx
   GEOMImpl_Gen.cxx
   GEOMImpl_PointDriver.cxx
   GEOMImpl_VectorDriver.cxx
index 6009804a356702a3e897a38f08882f46f3b3f356..bcca586a23aa84a254c96092bbf84d0131819b72 100644 (file)
 
 #include "GEOMImpl_CopyDriver.hxx"
 #include "GEOMImpl_ICopy.hxx"
+#include "GEOMImpl_ITransferData.hxx"
 #include "GEOMImpl_Types.hxx"
 #include "GEOM_Function.hxx"
 #include "GEOM_Object.hxx"
+#include "GEOMAlgo_GetInPlace.hxx"
 
+#include <Bnd_Box.hxx>
 #include <BRep_Tool.hxx>
+#include <BRepBndLib.hxx>
 #include <gp_Pnt.hxx>
+#include <Precision.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopAbs.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TNaming_CopyShape.hxx>
 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_MapIteratorOfMapOfShape.hxx>
+
+
+#define NB_DATUM             2
+#define DATUM_NAME_INDEX     1
+#define DATUM_MATERIAL_INDEX 2
+
 
 //=======================================================================
 //function : GetID
@@ -65,6 +83,10 @@ Standard_Integer GEOMImpl_CopyDriver::Execute(TFunction_Logbook& log) const
 
   Standard_Integer aType = aFunction->GetType();
 
+  if (aType == TRANSFER_DATA) {
+    return transferData(log);
+  }
+
   GEOMImpl_ICopy aCI (aFunction);
   TopoDS_Shape aCopy;
   
@@ -129,6 +151,189 @@ GetCreationInformation(std::string&             theOperationName,
   return true;
 }
 
+//================================================================================
+/*!
+ * \brief Performs Transfer Data operation.
+ */
+//================================================================================
+
+Standard_Integer GEOMImpl_CopyDriver::transferData(TFunction_Logbook& log) const
+{
+  Handle(GEOM_Function)  aFunction = GEOM_Function::GetFunction(Label());
+  GEOMImpl_ITransferData aTD (aFunction);
+  Handle(GEOM_Function)  aRef1     = aTD.GetRef1();
+  Handle(GEOM_Function)  aRef2     = aTD.GetRef2();
+
+  if (aRef1.IsNull() || aRef2.IsNull()) {
+    return 0;
+  }
+
+  TopoDS_Shape                              aShape1     = aRef1->GetValue();
+  TopoDS_Shape                              aShape2     = aRef2->GetValue();
+  const int                                 aFindMethod = aTD.GetFindMethod();
+  TopTools_IndexedDataMapOfShapeListOfShape aMapSoDest;
+  Standard_Integer                          i;
+  TopTools_IndexedMapOfShape                anIndices1;
+  Standard_Integer                          aNbShapes;
+
+  TopExp::MapShapes(aShape1, anIndices1);
+  aNbShapes = anIndices1.Extent();
+
+  switch (aFindMethod) {
+    case TD_GET_IN_PLACE:
+      {
+        // Compute confusion tolerance.
+        Standard_Real    aTolConf = Precision::Confusion();
+
+        for (i = 0; i < 2; ++i) {
+          TopExp_Explorer anExp(i == 0 ? aShape1 : aShape2, TopAbs_VERTEX);
+
+          for (; anExp.More(); anExp.Next()) {
+            const TopoDS_Vertex aVtx = TopoDS::Vertex(anExp.Current());
+            const Standard_Real aTolVtx = BRep_Tool::Tolerance(aVtx);
+
+            if (aTolVtx > aTolConf) {
+              aTolConf = aTolVtx;
+            }
+          }
+        }
+
+        // Compute mass tolerance.
+        Bnd_Box       aBoundingBox;
+        Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+        Standard_Real aMassTol;
+
+        BRepBndLib::Add(aShape1, aBoundingBox);
+        BRepBndLib::Add(aShape2, aBoundingBox);
+        aBoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+        aMassTol = Max(aXmax - aXmin, aYmax - aYmin);
+        aMassTol = Max(aMassTol, aZmax - aZmin);
+        aMassTol *= aTolConf;
+
+        // Searching for the sub-shapes inside the ShapeWhere shape
+        GEOMAlgo_GetInPlace aGIP;
+        aGIP.SetTolerance(aTolConf);
+        aGIP.SetTolMass(aMassTol);
+        aGIP.SetTolCG(aTolConf);
+
+        aGIP.SetArgument(aShape1);
+        aGIP.SetShapeWhere(aShape2);
+
+        aGIP.Perform();
+
+        int iErr = aGIP.ErrorStatus();
+
+        if (iErr) {
+          return 0;
+        }
+
+        const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesIn = aGIP.ShapesIn();
+        const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesOn = aGIP.ShapesOn();
+        Standard_Integer                         j;
+
+        for (j = 1; j <= aNbShapes; ++j) {
+          const TopoDS_Shape   &aSource = anIndices1.FindKey(j);
+          TopTools_ListOfShape  aListShapes2;
+          TopTools_MapOfShape   aMapShapes2;
+
+          for (i = 0; i < 2; ++i) {
+            const GEOMAlgo_DataMapOfShapeMapOfShape &aShapes2 =
+                          i == 0 ? aShapesIn : aShapesOn;
+
+            if (aShapes2.IsBound(aSource)) {
+              const TopTools_MapOfShape &aMapShapesDest =
+                aShapes2.Find(aSource);
+              TopTools_MapIteratorOfMapOfShape aMapIter(aMapShapesDest);
+
+              for (; aMapIter.More(); aMapIter.Next()) {
+                const TopoDS_Shape &aShapeDest = aMapIter.Key();
+
+                if (aMapShapes2.Add(aShapeDest)) {
+                  aListShapes2.Append(aShapeDest);
+                }
+              }
+            }
+          }
+
+          if (!aListShapes2.IsEmpty()) {
+            aMapSoDest.Add(aSource, aListShapes2);
+          }
+        }
+      }
+      break;
+    case TD_GET_IN_PLACE_OLD:
+    case TD_GET_IN_PLACE_BY_HISTORY:
+    default:
+      return 0;
+  }
+
+  // Perform copying names.
+  Handle(TColStd_HArray1OfExtendedString) aDatumName   =
+    new TColStd_HArray1OfExtendedString(1, NB_DATUM);
+  Handle(TColStd_HArray1OfInteger)        aDatumMaxVal =
+    new TColStd_HArray1OfInteger(1, NB_DATUM, 0);
+  Handle(TColStd_HArray1OfInteger)        aDatumVal    =
+    new TColStd_HArray1OfInteger(1, NB_DATUM, 0);
+  GEOMImpl_ITransferData                  aTD1(aRef1);
+  GEOMImpl_ITransferData                  aTD2(aRef2);
+
+  aDatumName->SetValue(DATUM_NAME_INDEX,     "GEOM_TRANSFER_DATA_NAMES");
+  aDatumName->SetValue(DATUM_MATERIAL_INDEX, "GEOM_TRANSFER_DATA_MATERIALS");
+
+  for (i = 1; i <= aNbShapes; ++i) {
+    const TopoDS_Shape      &aSource   = anIndices1.FindKey(i);
+    TCollection_AsciiString  aName     = aTD1.GetName(aSource);
+    TCollection_AsciiString  aMaterial = aTD1.GetMaterial(aSource);
+
+    // Transfer name
+    if (!aName.IsEmpty()) {
+      aDatumMaxVal->ChangeValue(DATUM_NAME_INDEX)++;
+
+      if (aMapSoDest.Contains(aSource)) {
+        aDatumVal->ChangeValue(DATUM_NAME_INDEX)++;
+
+        // Copy name to the list of subshapes of the second shape.
+        const TopTools_ListOfShape         &aListDest =
+          aMapSoDest.FindFromKey(aSource);
+        TopTools_ListIteratorOfListOfShape  anIt(aListDest);
+
+        for (; anIt.More(); anIt.Next()) {
+          const TopoDS_Shape &aShapeDest = anIt.Value();
+
+          aTD2.SetName(aShapeDest, aName);
+        }
+      }
+    }
+
+    // Transfer Material
+    if (!aMaterial.IsEmpty()) {
+      aDatumMaxVal->ChangeValue(DATUM_MATERIAL_INDEX)++;
+
+      if (aMapSoDest.Contains(aSource)) {
+        aDatumVal->ChangeValue(DATUM_MATERIAL_INDEX)++;
+
+        // Copy material to the list of subshapes of the second shape.
+        const TopTools_ListOfShape         &aListDest =
+          aMapSoDest.FindFromKey(aSource);
+        TopTools_ListIteratorOfListOfShape  anIt(aListDest);
+
+        for (; anIt.More(); anIt.Next()) {
+          const TopoDS_Shape &aShapeDest = anIt.Value();
+
+          aTD2.SetMaterial(aShapeDest, aMaterial);
+        }
+      }
+    }
+  }
+
+  // Store results.
+  aTD.SetDatumName(aDatumName);
+  aTD.SetDatumMaxVal(aDatumMaxVal);
+  aTD.SetDatumVal(aDatumVal);
+
+  return 1;
+}
+
 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_CopyDriver,GEOM_BaseDriver);
 
 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_CopyDriver,GEOM_BaseDriver);
index 66380dbb33dfe60354368de31a3b7e4cc0f12b3d..f4a755b20a92ccc03a61d11e0fbf694147e0ecf0 100644 (file)
@@ -82,6 +82,11 @@ Standard_EXPORT ~GEOMImpl_CopyDriver() {};
                               std::vector<GEOM_Param>& params);
 
 DEFINE_STANDARD_RTTI( GEOMImpl_CopyDriver )
+
+private:
+
+  Standard_Integer transferData(TFunction_Logbook& log) const;
+
 };
 
 #endif
index 925e547aac8747e360237bc6596ce670ac22d731..047b17ac125d553f088001dc185356a83584ca64 100644 (file)
@@ -399,6 +399,29 @@ bool GEOMImpl_IInsertOperations::TransferData
     return false;
   }
 
+  // Fill result list of data.
+  theResult.clear();
+
+  Handle(TColStd_HArray1OfExtendedString) aDatumName   = aTD.GetDatumName();
+  Handle(TColStd_HArray1OfInteger)        aDatumMaxVal = aTD.GetDatumMaxVal();
+  Handle(TColStd_HArray1OfInteger)        aDatumVal    = aTD.GetDatumVal();
+
+  if (!aDatumName.IsNull() && !aDatumMaxVal.IsNull() && !aDatumVal.IsNull()) {
+    Standard_Integer i;
+    Standard_Integer aNbDatum = aDatumName->Length();
+
+    for (i = 1; i <= aNbDatum; ++i) {
+      if (aDatumMaxVal->Value(i) > 0) {
+        TransferDatum aDatum;
+
+        aDatum.myName      = TCollection_AsciiString(aDatumName->Value(i));
+        aDatum.myNumber    = aDatumVal->Value(i);
+        aDatum.myMaxNumber = aDatumMaxVal->Value(i);
+        theResult.push_back(aDatum);
+      }
+    }
+  }
+
   //Make a Python command
   GEOM::TPythonDump pd (aFunction);
   pd << "geompy.TransferData(" << theObjectFrom << ", " << theObjectTo;
diff --git a/src/GEOMImpl/GEOMImpl_ITransferData.cxx b/src/GEOMImpl/GEOMImpl_ITransferData.cxx
new file mode 100644 (file)
index 0000000..d9e8f4d
--- /dev/null
@@ -0,0 +1,137 @@
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//NOTE: This is an intreface to a function for the Transfer Data functionality.
+//
+
+
+#include "GEOMImpl_ITransferData.hxx"
+
+#include <TDataStd_Comment.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDF_ChildIDIterator.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+
+
+//=============================================================================
+/*!
+ *  SetName
+ */
+//=============================================================================
+void GEOMImpl_ITransferData::SetStringData
+                  (const TopoDS_Shape            &theSubShape,
+                   const TCollection_AsciiString &theData,
+                   const Standard_Boolean         IsName)
+{
+  TDF_Label           aLabel;
+  TDF_ChildIDIterator anIt
+    (_func->GetNamingEntry(), TDataStd_Name::GetID(), Standard_True);
+
+  for (; anIt.More(); anIt.Next()) {
+    Handle(TDataStd_Name) aNameAttr =
+        Handle(TDataStd_Name)::DownCast(anIt.Value());
+
+    if (aNameAttr.IsNull()) {
+      continue;
+    }
+
+    TDF_Label aLab = aNameAttr->Label();
+    Handle(TNaming_NamedShape) aShAttr;
+
+    if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aShAttr) &&
+        aShAttr->Get().IsEqual(theSubShape)) {
+      aLabel = aLab;
+      break;
+    }
+  }
+
+  if (aLabel.IsNull()) {
+    TDF_TagSource aTag;
+
+    aLabel = aTag.NewChild(_func->GetNamingEntry());
+
+    TNaming_Builder aTnBuild (aLabel);
+
+    aTnBuild.Generated(theSubShape);
+  }
+
+  // set a name or a material
+  TCollection_ExtendedString aDataExt(theData);
+
+  if (IsName) {
+    TDataStd_Name::Set(aLabel, aDataExt);
+  } else {
+    TDataStd_Comment::Set(aLabel, aDataExt);
+  }
+}
+
+//=============================================================================
+/*!
+ *  GetStringData
+ */
+//=============================================================================
+TCollection_AsciiString GEOMImpl_ITransferData::GetStringData
+                  (const TopoDS_Shape     &theSubShape,
+                   const Standard_Boolean  IsName)
+{
+  // check all named shapes using iterator
+  TCollection_AsciiString aResult;
+  TDF_ChildIDIterator     anIt
+    (_func->GetNamingEntry(), TNaming_NamedShape::GetID(), Standard_True);
+
+  for (; anIt.More(); anIt.Next()) {
+    Handle(TNaming_NamedShape) aShAttr =
+        Handle(TNaming_NamedShape)::DownCast(anIt.Value());
+
+    if (aShAttr.IsNull()) {
+      continue;
+    }
+
+    if (aShAttr->Get().IsEqual(theSubShape)) {
+      TDF_Label        aLabel  = aShAttr->Label();
+      Standard_Boolean isFound = Standard_False;
+
+      if (IsName) {
+        Handle(TDataStd_Name) aString;
+
+        if(aLabel.FindAttribute(TDataStd_Name::GetID(), aString)) {
+          aResult = TCollection_AsciiString(aString->Get());
+          isFound = Standard_True;
+        }
+      } else {
+        Handle(TDataStd_Comment) aString;
+
+        if(aLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) {
+          aResult = TCollection_AsciiString(aString->Get());
+          isFound = Standard_True;
+        }
+      }
+
+      if (isFound) {
+        break;
+      }
+    }
+  }
+
+  return aResult;
+}
index 2e7e55eed0d50c596ea9f62487fb25eb5a3550c7..761ed19e2a2b7fe37458985e55797f982c2fe2cd 100644 (file)
 
 //NOTE: This is an intreface to a function for the Transfer Data functionality.
 //
+
+
+#ifndef _GEOMImpl_ITransferData_HXX_
+#define _GEOMImpl_ITransferData_HXX_
+
+
+#include "GEOM_GEOMImpl.hxx"
 #include "GEOM_Function.hxx"
 
-#define TD_ARG_REF1   1
-#define TD_ARG_REF2   2
-#define TD_ARG_METHOD 3
+#include <TColStd_HArray1OfInteger.hxx>
+
+
+#define TD_ARG_REF1            1
+#define TD_ARG_REF2            2
+#define TD_ARG_METHOD          3
+#define TD_ARG_DATUM_NAME      4
+#define TD_ARG_DATUM_MAX_VALUE 5
+#define TD_ARG_DATUM_VALUE     6
 
 class GEOMImpl_ITransferData
 {
@@ -50,7 +63,52 @@ class GEOMImpl_ITransferData
 
   int GetFindMethod() { return _func->GetInteger(TD_ARG_METHOD); }
 
+  void SetDatumName(const Handle(TColStd_HArray1OfExtendedString) &theDatumName)
+  { _func->SetStringArray(TD_ARG_DATUM_NAME, theDatumName); }
+
+  Handle(TColStd_HArray1OfExtendedString) GetDatumName()
+  { return _func->GetStringArray(TD_ARG_DATUM_NAME); }
+
+  void SetDatumMaxVal(const Handle(TColStd_HArray1OfInteger) &theDatumMaxVal)
+  { _func->SetIntegerArray(TD_ARG_DATUM_MAX_VALUE, theDatumMaxVal); }
+
+  Handle(TColStd_HArray1OfInteger) GetDatumMaxVal()
+  { return _func->GetIntegerArray(TD_ARG_DATUM_MAX_VALUE); }
+
+  void SetDatumVal(const Handle(TColStd_HArray1OfInteger) &theDatumVal)
+  { _func->SetIntegerArray(TD_ARG_DATUM_VALUE, theDatumVal); }
+
+  Handle(TColStd_HArray1OfInteger) GetDatumVal()
+  { return _func->GetIntegerArray(TD_ARG_DATUM_VALUE); }
+
+  GEOMIMPL_EXPORT void SetName(const TopoDS_Shape            &theSubShape,
+                                const TCollection_AsciiString &theName)
+  { SetStringData(theSubShape, theName, Standard_True); }
+
+  GEOMIMPL_EXPORT TCollection_AsciiString GetName
+                               (const TopoDS_Shape &theSubShape)
+  { return GetStringData(theSubShape, Standard_True); }
+
+  GEOMIMPL_EXPORT void SetMaterial(const TopoDS_Shape         &theSubShape,
+                                   const TCollection_AsciiString &theName)
+  { SetStringData(theSubShape, theName, Standard_False); }
+
+  GEOMIMPL_EXPORT TCollection_AsciiString GetMaterial
+                               (const TopoDS_Shape &theSubShape)
+  { return GetStringData(theSubShape, Standard_False); }
+
+ private:
+
+  TCollection_AsciiString GetStringData(const TopoDS_Shape     &theSubShape,
+                                        const Standard_Boolean  IsName);
+
+  void SetStringData(const TopoDS_Shape            &theSubShape,
+                     const TCollection_AsciiString &theData,
+                     const Standard_Boolean         IsName);
+
  private:
 
   Handle(GEOM_Function) _func;
 };
+
+#endif
index 53d63d118aa728c657733439f54c9c9ed8364151..3697c2afa6426c2021568ee57f409e5bddd9bd24 100644 (file)
@@ -143,7 +143,7 @@ void OperationGUI_TransferDataDlg::ClickOnOk()
 //=================================================================================
 bool OperationGUI_TransferDataDlg::ClickOnApply()
 {
-  if (!onAccept())
+  if (!onAccept(false))
     return false;
   // activate first line edit
   myGroup->PushButton1->click();
@@ -157,7 +157,7 @@ bool OperationGUI_TransferDataDlg::ClickOnApply()
 void OperationGUI_TransferDataDlg::SelectionIntoArgument()
 {
   GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
-    
+
   if (aSelectedObject) {
     myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
 
@@ -305,8 +305,8 @@ bool OperationGUI_TransferDataDlg::execute (ObjectList& objects)
     if (aNbTypes == 0) {
       aMsg = tr("GEOM_TRANSFER_DATA_NOT_COPIED");
     } else {
-      aMsg = tr("GEOM_TRANSFER_DATA_COPIED\n");
-
+      aMsg = tr("GEOM_TRANSFER_DATA_COPIED");
+      aMsg += "\n";
       int i;
 
       for (i = 0; i < aNbTypes; i++ ) {
@@ -323,6 +323,8 @@ bool OperationGUI_TransferDataDlg::execute (ObjectList& objects)
     SUIT_MessageBox::information
             (SUIT_Session::session()->activeApplication()->desktop(),
              tr("GEOM_TRANSFER_DATA_INFO"), aMsg, tr("BUT_OK"));
+
+    objects.push_back(myObject2.copy());
   }
 
   return isOK;