From: skv Date: Wed, 10 Dec 2014 08:04:29 +0000 (+0300) Subject: Implement data transfering X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bb28e1dca6018568433c07cbb5fff39258355b72;p=modules%2Fgeom.git Implement data transfering --- diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 7b2e3b8f9..43b4de74d 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -7198,5 +7198,21 @@ Do you want to create new material? GEOM_TRANSFER_DATA_INFO Transfer Data: Information + + GEOM_TRANSFER_DATA_NOT_COPIED + There is nothing to be copied. + + + GEOM_TRANSFER_DATA_COPIED + The following data is copied: + + + GEOM_TRANSFER_DATA_NAMES + Names: %1 of %2 + + + GEOM_TRANSFER_DATA_MATERIALS + Materials: %1 of %2 + diff --git a/src/GEOMImpl/CMakeLists.txt b/src/GEOMImpl/CMakeLists.txt index 3828848e5..f9a063d5d 100755 --- a/src/GEOMImpl/CMakeLists.txt +++ b/src/GEOMImpl/CMakeLists.txt @@ -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 diff --git a/src/GEOMImpl/GEOMImpl_CopyDriver.cxx b/src/GEOMImpl/GEOMImpl_CopyDriver.cxx index 6009804a3..bcca586a2 100644 --- a/src/GEOMImpl/GEOMImpl_CopyDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_CopyDriver.cxx @@ -22,18 +22,36 @@ #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 #include +#include #include +#include #include #include #include #include +#include +#include #include #include +#include +#include +#include +#include +#include + + +#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); diff --git a/src/GEOMImpl/GEOMImpl_CopyDriver.hxx b/src/GEOMImpl/GEOMImpl_CopyDriver.hxx index 66380dbb3..f4a755b20 100644 --- a/src/GEOMImpl/GEOMImpl_CopyDriver.hxx +++ b/src/GEOMImpl/GEOMImpl_CopyDriver.hxx @@ -82,6 +82,11 @@ Standard_EXPORT ~GEOMImpl_CopyDriver() {}; std::vector& params); DEFINE_STANDARD_RTTI( GEOMImpl_CopyDriver ) + +private: + + Standard_Integer transferData(TFunction_Logbook& log) const; + }; #endif diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx index 925e547aa..047b17ac1 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -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 index 000000000..d9e8f4d77 --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_ITransferData.cxx @@ -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 +#include +#include +#include +#include + + +//============================================================================= +/*! + * 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; +} diff --git a/src/GEOMImpl/GEOMImpl_ITransferData.hxx b/src/GEOMImpl/GEOMImpl_ITransferData.hxx index 2e7e55eed..761ed19e2 100644 --- a/src/GEOMImpl/GEOMImpl_ITransferData.hxx +++ b/src/GEOMImpl/GEOMImpl_ITransferData.hxx @@ -22,11 +22,24 @@ //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 + + +#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 diff --git a/src/OperationGUI/OperationGUI_TransferDataDlg.cxx b/src/OperationGUI/OperationGUI_TransferDataDlg.cxx index 53d63d118..3697c2afa 100644 --- a/src/OperationGUI/OperationGUI_TransferDataDlg.cxx +++ b/src/OperationGUI/OperationGUI_TransferDataDlg.cxx @@ -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;