diff --git a/doc/salome/gui/GEOM/images/transfer_data1.png b/doc/salome/gui/GEOM/images/transfer_data1.png new file mode 100644 index 000000000..4cd196163 Binary files /dev/null and b/doc/salome/gui/GEOM/images/transfer_data1.png differ diff --git a/doc/salome/gui/GEOM/images/transfer_data2.png b/doc/salome/gui/GEOM/images/transfer_data2.png new file mode 100644 index 000000000..374147d7d Binary files /dev/null and b/doc/salome/gui/GEOM/images/transfer_data2.png differ diff --git a/doc/salome/gui/GEOM/input/transfer_data.doc b/doc/salome/gui/GEOM/input/transfer_data.doc new file mode 100644 index 000000000..b34b34f31 --- /dev/null +++ b/doc/salome/gui/GEOM/input/transfer_data.doc @@ -0,0 +1,53 @@ +/*! + +\page transfer_data_page Transfer Data + +This operation performs copying of non-topological data +from one shape to another. The topology of the destination object +will not change, only non-topological data will be transferred +(if it is present in the source object). It is possible to transfer +the following data with this operation: + + +To use this operation, select in the Main Menu Operations -> Transfer Data. +The following dialog box will appear. + +\image html transfer_data1.png "Transfer Data Dialog" + +In this dialog: + + +To copy data click on \b Apply or Apply and Close button. As the result +it is possible to see how many names and materials are copied as well as +maximum number of names and materials available for copying. This information is +provided on the following message box: + +\image html transfer_data2.png "Transfer Data Information" + +TUI Command: geompy.TransferData(ObjectFrom, ObjectTo, FindMethod), +
where \em ObjectFrom is a data source object, \em ObjectTo is a +destination object and \em FindMethod is a same shape detection method with +default value \em GEOM.FSM_GetInPlace. + +Our TUI Scripts provide you with useful example of the use of +\ref swig_TransferData "Transfer Data" functionality. + +*/ diff --git a/doc/salome/gui/GEOM/input/transforming_geom_objs.doc b/doc/salome/gui/GEOM/input/transforming_geom_objs.doc index 573182a4d..8ded8676a 100644 --- a/doc/salome/gui/GEOM/input/transforming_geom_objs.doc +++ b/doc/salome/gui/GEOM/input/transforming_geom_objs.doc @@ -25,6 +25,8 @@ into water. special case of \b Explode operation.
  • \subpage shared_shapes_page "Get shared shapes" operation, a special case of \b Explode operation.
  • +
  • \subpage transfer_data_page "Transfer Data" operation, which copies +non-topological data from one shape to another.
  • \subpage restore_presentation_parameters_page "Restore presentation parameters". diff --git a/doc/salome/gui/GEOM/input/tui_test_others.doc b/doc/salome/gui/GEOM/input/tui_test_others.doc index 701a1b52b..86630b77d 100644 --- a/doc/salome/gui/GEOM/input/tui_test_others.doc +++ b/doc/salome/gui/GEOM/input/tui_test_others.doc @@ -96,6 +96,9 @@ \anchor swig_GetSharedShapes \until "sharedEdge_" +\anchor swig_TransferData +\until subBlackWhite[1] + \anchor swig_CheckAndImprove \until "blocksComp" diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index dc9cf2f92..78e9bfca2 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -115,7 +115,8 @@ module GEOM * \brief Kind of method to find inside one main shape some sub-shapes, * corresponding to other given shape (its argument) * - * Is used in functions GEOM_Gen.RestoreSubShapesO(), GEOM_Gen.RestoreSubShapesSO() + * Is used in functions GEOM_Gen.RestoreSubShapesO(), GEOM_Gen.RestoreSubShapesSO(), + * TransferNames() */ enum find_shape_method { @@ -139,7 +140,10 @@ module GEOM /*! To be used only for multi-transformation result. * Only this method can be used after multi-transformation. */ - FSM_MultiTransformed + FSM_MultiTransformed, + + /*! Use old GetInPlace functionality. */ + FSM_GetInPlace_Old }; /*! @@ -3976,7 +3980,41 @@ module GEOM * \return list of all texture IDs avaiable for the current study */ ListOfLong GetAllTextures(); - + + /*! + * \brief Non-topological information transfer datum. + */ + struct TransferDatum + { + string myName; + long myNumber; + long myMaxNumber; + }; + + /*! + * \brief Sequence of non-topological information tranfer data. + */ + typedef sequence ListOfTransferDatum; + + /*! + * \brief Transfer non-topological data from one object to another + * \param theObjectFrom the source object of non-topological data + * \param theObjectTo the destination object of non-topological data + * \param theFindMethod method to search sub-shapes of theObjectFrom + * in shape theObjectTo. Possible values are: GEOM::FSM_GetInPlace, + * GEOM::FSM_GetInPlaceByHistory and GEOM::FSM_GetInPlace_Old. + * Other values of GEOM::find_shape_method are not supported. + * \param theResult statistics of the operation. Output parameter. It + * represents a sequence of Transfer Datum. A datum has the type + * (string code), the total number of items of this type and + * the number of transfered items. + * \return true in case of success; otherwise false. + */ + boolean TransferData(in GEOM_Object theObjectFrom, + in GEOM_Object theObjectTo, + in find_shape_method theFindMethod, + out ListOfTransferDatum theResult); + }; // # GEOM_IKindOfShape: diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index d887216b3..60ea6bd8a 100755 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -184,6 +184,7 @@ SET( _res_files torus.png torusdxyz.png toruspointvector.png + transfer_data.png translationDxyz.png translationPoints.png translationVector.png diff --git a/resources/transfer_data.png b/resources/transfer_data.png new file mode 100644 index 000000000..275444be8 Binary files /dev/null and b/resources/transfer_data.png differ diff --git a/src/GEOMAlgo/CMakeLists.txt b/src/GEOMAlgo/CMakeLists.txt index d85a789f1..0e30b8b26 100755 --- a/src/GEOMAlgo/CMakeLists.txt +++ b/src/GEOMAlgo/CMakeLists.txt @@ -23,6 +23,8 @@ INCLUDE_DIRECTORIES( ${CAS_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS} + ${PROJECT_SOURCE_DIR}/src/GEOMUtils + ${PROJECT_SOURCE_DIR}/src/GEOM ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -34,6 +36,7 @@ ADD_DEFINITIONS( # libraries to link to SET(_link_LIBRARIES ${CAS_KERNEL} ${CAS_TKBool} ${CAS_TKBO} ${CAS_TKMesh} + GEOMbasic GEOMUtils ${KERNEL_SALOMELocalTrace} ) @@ -60,6 +63,7 @@ SET(GEOMAlgo_HEADERS GEOMAlgo_FinderShapeOn2.hxx GEOMAlgo_FinderShapeOnQuad.hxx GEOMAlgo_GetInPlace.hxx + GEOMAlgo_GetInPlaceAPI.hxx GEOMAlgo_GlueAnalyser.hxx GEOMAlgo_GlueDetector.hxx GEOMAlgo_Gluer.hxx @@ -123,6 +127,7 @@ SET(GEOMAlgo_SOURCES GEOMAlgo_GetInPlace_1.cxx GEOMAlgo_GetInPlace_2.cxx GEOMAlgo_GetInPlace_3.cxx + GEOMAlgo_GetInPlaceAPI.cxx GEOMAlgo_GlueAnalyser.cxx GEOMAlgo_GlueDetector.cxx GEOMAlgo_Gluer.cxx @@ -142,7 +147,7 @@ SET(GEOMAlgo_SOURCES GEOMAlgo_ShapeInfoFiller.cxx GEOMAlgo_ShapeInfoFiller_1.cxx GEOMAlgo_ShapeSolid.cxx - GEOMAlgo_ShellSolid.cxx + GEOMAlgo_ShellSolid.cxx GEOMAlgo_SolidSolid.cxx GEOMAlgo_Splitter.cxx GEOMAlgo_StateCollector.cxx diff --git a/src/GEOMAlgo/FILES b/src/GEOMAlgo/FILES index 898eca027..aa1e05e72 100644 --- a/src/GEOMAlgo/FILES +++ b/src/GEOMAlgo/FILES @@ -54,6 +54,8 @@ GEOMAlgo_GetInPlace.cxx GEOMAlgo_GetInPlace_1.cxx GEOMAlgo_GetInPlace_2.cxx GEOMAlgo_GetInPlace_3.cxx +GEOMAlgo_GetInPlaceAPI.hxx +GEOMAlgo_GetInPlaceAPI.cxx GEOMAlgo_Splitter.hxx GEOMAlgo_Splitter.cxx GEOMAlgo_ShapeInfoFiller.hxx diff --git a/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx new file mode 100644 index 000000000..f531ba16e --- /dev/null +++ b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.cxx @@ -0,0 +1,450 @@ +// 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 +// +// File: GEOMAlgo_GetInPlaceAPI.cxx +// Created: +// Author: Sergey KHROMOV + + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//======================================================================= +//function : GetInPlace +//purpose : +//======================================================================= +Standard_Boolean GEOMAlgo_GetInPlaceAPI::GetInPlace + (const TopoDS_Shape &theWhere, + const TopoDS_Shape &theWhat, + GEOMAlgo_GetInPlace &theGIP) +{ + if (theWhere.IsNull() || theWhat.IsNull()) { + return Standard_False; + } + + // Compute confusion tolerance. + Standard_Real aTolConf = Precision::Confusion(); + Standard_Integer i; + + for (i = 0; i < 2; ++i) { + TopExp_Explorer anExp(i == 0 ? theWhere : theWhat, 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(theWhere, aBoundingBox); + BRepBndLib::Add(theWhat, 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 + theGIP.SetTolerance(aTolConf); + theGIP.SetTolMass(aMassTol); + theGIP.SetTolCG(aTolConf); + + theGIP.SetArgument(theWhat); + theGIP.SetShapeWhere(theWhere); + + theGIP.Perform(); + + int iErr = theGIP.ErrorStatus(); + + if (iErr) { + return Standard_False; + } + + return Standard_True; +} + +//======================================================================= +//function : GetInPlaceOld +//purpose : +//======================================================================= +Standard_Integer GEOMAlgo_GetInPlaceAPI::GetInPlaceOld + (const TopoDS_Shape &theWhere, + const TopoDS_Shape &theWhat, + TopTools_ListOfShape &theShapesInPlace) +{ + theShapesInPlace.Clear(); + + if (theWhere.IsNull() || theWhat.IsNull()) { + // Error: aWhere and aWhat TopoDS_Shape are Null. + return 1; + } + + TopoDS_Shape aPntShape; + TopoDS_Vertex aVertex; + bool isFound = false; + TopAbs_ShapeEnum iType = TopAbs_SOLID; + //Standard_Real aWhat_Mass = 0., aWhere_Mass = 0.; + Standard_Real tab_aWhat[4], tab_aWhere[4]; + Standard_Real dl_l = 1e-3; + Standard_Real min_l, Tol_0D, Tol_1D, Tol_2D, Tol_3D, Tol_Mass; + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + Bnd_Box BoundingBox; + gp_Pnt aPnt, aPnt_aWhat, tab_Pnt[2]; + GProp_GProps aProps; + + iType = GEOMUtils::GetTypeOfSimplePart(theWhat); + if (iType == TopAbs_SHAPE) { + // Error: An attempt to extract a shape of not supported type. + return 2; + } + + TopExp_Explorer Exp_aWhat ( theWhat, iType ); + TopExp_Explorer Exp_aWhere ( theWhere, iType ); + TopExp_Explorer Exp_Edge ( theWhere, TopAbs_EDGE ); + + // Find the shortest edge in theShapeWhere shape + BRepBndLib::Add(theWhere, BoundingBox); + BoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + min_l = fabs(aXmax - aXmin); + if( min_l < fabs(aYmax - aYmin) ) min_l = fabs(aYmax - aYmin); + if( min_l < fabs(aZmax - aZmin) ) min_l = fabs(aZmax - aZmin); + min_l /= dl_l; + // Mantis issue 0020908 BEGIN + if (!Exp_Edge.More()) { + min_l = Precision::Confusion(); + } + // Mantis issue 0020908 END + for ( Standard_Integer nbEdge = 0; Exp_Edge.More(); Exp_Edge.Next(), nbEdge++ ) { + TopExp_Explorer Exp_Vertex( Exp_Edge.Current(), TopAbs_VERTEX); + for ( Standard_Integer nbVertex = 0; Exp_Vertex.More(); Exp_Vertex.Next(), nbVertex++ ) { + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( Exp_Vertex.Current() ) ); + tab_Pnt[nbVertex] = aPnt; + } + if ( ! tab_Pnt[0].IsEqual(tab_Pnt[1], dl_l) ) { + BRepGProp::LinearProperties(Exp_Edge.Current(), aProps); + if ( aProps.Mass() < min_l ) min_l = aProps.Mass(); + } + } + + // Compute tolerances + Tol_0D = dl_l; + Tol_1D = dl_l * min_l; + Tol_2D = dl_l * ( min_l * min_l) * ( 2. + dl_l); + Tol_3D = dl_l * ( min_l * min_l * min_l ) * ( 3. + (3 * dl_l) + (dl_l * dl_l) ); + + if (Tol_0D < Precision::Confusion()) Tol_0D = Precision::Confusion(); + if (Tol_1D < Precision::Confusion()) Tol_1D = Precision::Confusion(); + if (Tol_2D < Precision::Confusion()) Tol_2D = Precision::Confusion(); + if (Tol_3D < Precision::Confusion()) Tol_3D = Precision::Confusion(); + + Tol_Mass = Tol_3D; + if ( iType == TopAbs_VERTEX ) Tol_Mass = Tol_0D; + else if ( iType == TopAbs_EDGE ) Tol_Mass = Tol_1D; + else if ( iType == TopAbs_FACE ) Tol_Mass = Tol_2D; + + // Searching for the sub-shapes inside the ShapeWhere shape + TopTools_MapOfShape map_aWhere; + for ( Exp_aWhere.ReInit(); Exp_aWhere.More(); Exp_aWhere.Next() ) { + if (!map_aWhere.Add(Exp_aWhere.Current())) + continue; // skip repeated shape to avoid mass addition + GetShapeProperties( Exp_aWhere.Current(), tab_aWhere, aPnt ); + for ( Exp_aWhat.ReInit(); Exp_aWhat.More(); Exp_aWhat.Next() ) { + GetShapeProperties( Exp_aWhat.Current(), tab_aWhat, aPnt_aWhat ); + if ( fabs(tab_aWhat[3] - tab_aWhere[3]) <= Tol_Mass && aPnt_aWhat.Distance(aPnt) <= Tol_1D ) + isFound = true; + else { + if ( (tab_aWhat[3] - tab_aWhere[3]) > Tol_Mass ) { + aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape(); + aVertex = TopoDS::Vertex( aPntShape ); + BRepExtrema_DistShapeShape aWhereDistance ( aVertex, Exp_aWhere.Current() ); + BRepExtrema_DistShapeShape aWhatDistance ( aVertex, Exp_aWhat.Current() ); + if ( aWhereDistance.IsDone() && aWhatDistance.IsDone() && + fabs(aWhereDistance.Value() - aWhatDistance.Value()) <= Tol_1D ) + { + // 0020162: "EDF 961 GEOM : Getinplace is getting additionnal orthogonal faces" + // aVertex must be projected to the same point on Where and on What + gp_Pnt pOnWhat = aWhatDistance.PointOnShape2(1); + gp_Pnt pOnWhere = aWhereDistance.PointOnShape2(1); + isFound = ( pOnWhat.Distance(pOnWhere) <= Tol_1D ); + if ( isFound && iType == TopAbs_FACE ) + { + // check normals at pOnWhat and pOnWhere + const double angleTol = M_PI/180.; + gp_Vec normToWhat = GetNormal( TopoDS::Face(Exp_aWhat.Current()), aWhatDistance); + gp_Vec normToWhere = GetNormal( TopoDS::Face(Exp_aWhere.Current()), aWhereDistance); + if ( normToWhat * normToWhere < 0 ) + normToWhat.Reverse(); + isFound = ( normToWhat.Angle( normToWhere ) < angleTol ); + } + } + } + } + if ( isFound ) { + theShapesInPlace.Append(Exp_aWhere.Current()); + //aWhere_Mass += tab_aWhere[3]; + isFound = false; + break; + } + } + } + + if (theShapesInPlace.Extent() == 0) { + // Not found any Results + return 3; + } + + return 0; +} + +//======================================================================= +//function : GetNormal +//purpose : +//======================================================================= +gp_Vec GEOMAlgo_GetInPlaceAPI::GetNormal + (const TopoDS_Face &theFace, + const BRepExtrema_DistShapeShape &theExtrema) +{ + gp_Vec defaultNorm(1,0,0); // to have same normals on different faces + try { + // get UV at extrema point + Standard_Real u,v, f,l; + switch ( theExtrema.SupportTypeShape2(1) ) { + case BRepExtrema_IsInFace: { + theExtrema.ParOnFaceS2(1, u, v ); + break; + } + case BRepExtrema_IsOnEdge: { + TopoDS_Edge edge = TopoDS::Edge( theExtrema.SupportOnShape2(1)); + Handle(Geom2d_Curve) pcurve = + BRep_Tool::CurveOnSurface(edge, theFace, f,l); + + theExtrema.ParOnEdgeS2( 1, u ); + gp_Pnt2d uv = pcurve->Value( u ); + u = uv.Coord(1); + v = uv.Coord(2); + break; + } + case BRepExtrema_IsVertex: return defaultNorm; + } + // get derivatives + BRepAdaptor_Surface surface( theFace, false ); + gp_Vec du, dv; gp_Pnt p; + surface.D1( u, v, p, du, dv ); + + return du ^ dv; + + } catch (Standard_Failure ) { + } + return defaultNorm; +} + +//======================================================================= +//function : GetShapeProperties +//purpose : +//======================================================================= +void GEOMAlgo_GetInPlaceAPI::GetShapeProperties(const TopoDS_Shape &theShape, + Standard_Real theTab[], + gp_Pnt &theVertex) +{ + GProp_GProps aProps; + gp_Pnt aCenterMass; + Standard_Real aShapeSize; + + if (theShape.ShapeType() == TopAbs_VERTEX) { + aCenterMass = BRep_Tool::Pnt(TopoDS::Vertex(theShape)); + } else if (theShape.ShapeType() == TopAbs_EDGE) { + BRepGProp::LinearProperties(theShape, aProps); + } else if (theShape.ShapeType() == TopAbs_FACE) { + BRepGProp::SurfaceProperties(theShape, aProps); + } else { + BRepGProp::VolumeProperties(theShape, aProps); + } + + if (theShape.ShapeType() == TopAbs_VERTEX) { + aShapeSize = 1; + } else { + aCenterMass = aProps.CentreOfMass(); + aShapeSize = aProps.Mass(); + } + + theVertex = aCenterMass; + theTab[0] = theVertex.X(); + theTab[1] = theVertex.Y(); + theTab[2] = theVertex.Z(); + theTab[3] = aShapeSize; +} + +//======================================================================= +//function : GetInPlaceByHistory +//purpose : +//======================================================================= +Standard_Boolean GEOMAlgo_GetInPlaceAPI::GetInPlaceByHistory + (const Handle(GEOM_Function) &theWhereFunction, + const TopTools_IndexedMapOfShape &theWhereIndices, + const TopoDS_Shape &theWhat, + TopTools_ListOfShape &theShapesInPlace) +{ + if (theWhereFunction.IsNull() || theWhat.IsNull()) + return Standard_False; + + if (theWhereIndices.Contains(theWhat)) { + // entity was not changed by the operation + theShapesInPlace.Append(theWhat); + + return Standard_True; + } + + // try to find in history + TDF_Label aHistoryLabel = theWhereFunction->GetHistoryEntry(Standard_False); + + // search in history for all argument shapes + Standard_Boolean isFound = Standard_False; + Standard_Boolean isGood = Standard_False; + + TDF_LabelSequence aLabelSeq; + theWhereFunction->GetDependency(aLabelSeq); + Standard_Integer nbArg = aLabelSeq.Length(); + + for (Standard_Integer iarg = 1; iarg <= nbArg && !isFound; iarg++) { + + TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg); + + Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel); + TopoDS_Shape anArgumentShape = anArgumentObject->GetValue(); + + TopTools_IndexedMapOfShape anArgumentIndices; + TopExp::MapShapes(anArgumentShape, anArgumentIndices); + + if (anArgumentIndices.Contains(theWhat)) { + isFound = Standard_True; + Standard_Integer aWhatIndex = anArgumentIndices.FindIndex(theWhat); + + // Find corresponding label in history + TDF_Label anArgumentHistoryLabel = + theWhereFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_False); + if (anArgumentHistoryLabel.IsNull()) { + // Lost History of operation argument. Possibly, all its entities was removed. + isGood = Standard_True; + } + else { + TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(aWhatIndex, Standard_False); + + if (aWhatHistoryLabel.IsNull()) { + // Removed entity ? Compound ? Compsolid ? Shell ? Wire + isGood = Standard_False; + } else { + Handle(TDataStd_IntegerArray) anIntegerArray; + if (!aWhatHistoryLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) { + //Error: Empty modifications history for the sought shape. + isGood = Standard_False; + } + else { + isGood = Standard_True; + Standard_Integer imod, aModifLen = anIntegerArray->Array()->Length(); + for (imod = 1; imod <= aModifLen; imod++) { + const Standard_Integer anIndex = + anIntegerArray->Array()->Value(imod); + + theShapesInPlace.Append(theWhereIndices.FindKey(anIndex)); + } + } + } + } + } + } + + isFound = isGood; + + if (!isFound) { + // try compound/compsolid/shell/wire element by element + Standard_Boolean isFoundAny = Standard_False; + TopTools_MapOfShape mapShape; + + if (theWhat.ShapeType() == TopAbs_COMPOUND || + theWhat.ShapeType() == TopAbs_COMPSOLID) { + // recursive processing of compound/compsolid + TopoDS_Iterator anIt (theWhat, Standard_True, Standard_True); + for (; anIt.More(); anIt.Next()) { + if (mapShape.Add(anIt.Value())) { + TopoDS_Shape curWhat = anIt.Value(); + isFoundAny = GetInPlaceByHistory(theWhereFunction, theWhereIndices, curWhat, theShapesInPlace); + if (isFoundAny) isFound = Standard_True; + } + } + } + else if (theWhat.ShapeType() == TopAbs_SHELL) { + // try to replace a shell by its faces images + TopExp_Explorer anExp (theWhat, TopAbs_FACE); + for (; anExp.More(); anExp.Next()) { + if (mapShape.Add(anExp.Current())) { + TopoDS_Shape curWhat = anExp.Current(); + isFoundAny = GetInPlaceByHistory(theWhereFunction, theWhereIndices, curWhat, theShapesInPlace); + if (isFoundAny) isFound = Standard_True; + } + } + } + else if (theWhat.ShapeType() == TopAbs_WIRE) { + // try to replace a wire by its edges images + TopExp_Explorer anExp (theWhat, TopAbs_EDGE); + for (; anExp.More(); anExp.Next()) { + if (mapShape.Add(anExp.Current())) { + TopoDS_Shape curWhat = anExp.Current(); + isFoundAny = GetInPlaceByHistory(theWhereFunction, theWhereIndices, curWhat, theShapesInPlace); + if (isFoundAny) isFound = Standard_True; + } + } + } + else { + // Removed entity + } + } + + return isFound; +} diff --git a/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx new file mode 100644 index 000000000..36ed52d46 --- /dev/null +++ b/src/GEOMAlgo/GEOMAlgo_GetInPlaceAPI.hxx @@ -0,0 +1,111 @@ +// 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 +// +// File: GEOMAlgo_GetInPlaceAPI.hxx +// Created: +// Author: Sergey KHROMOV + +#ifndef _GEOMAlgo_GetInPlaceAPI_HeaderFile +#define _GEOMAlgo_GetInPlaceAPI_HeaderFile + + +#include + +class GEOMAlgo_GetInPlace; +class Handle_GEOM_Function; +class BRepExtrema_DistShapeShape; +class TopoDS_Face; +class TopoDS_Shape; +class TopTools_IndexedMapOfShape; +class TopTools_ListOfShape; + + +/** + * This is an API class for all GetInPlace algorithm. + * It facilitates using different GetInPlace algorithms: + * a new one(GEOMAlgo_GetInPlace), an old one and + * GetInPlaceByHistory. + */ +class GEOMAlgo_GetInPlaceAPI +{ + +public: + + /** + * \brief New GetInPlace method implementation. + * Initializes the GEOMAlgo_GetInPlace object with correct parameters and + * performs computation (calls theGIP's method Perform. Returns + * Standard_True in face of success; Standard_False otherwise. + */ + Standard_EXPORT static Standard_Boolean GetInPlace + (const TopoDS_Shape &theWhere, + const TopoDS_Shape &theWhat, + GEOMAlgo_GetInPlace &theGIP); + + /*! + * \brief Old implementation of GetInPlace algoritm. + * This method searches among sub shapes of the shape theWhere parts that are + * coincident with the shape theWhat. The result list of shape is returned as + * an output parameter. It returns the error code with the following possible + * values: + * 0 - Success; + * 1 - theWhere and/or theWhat TopoDS_Shape are Null; + * 2 - An attempt to extract a shape of not supported type; + * 3 - Not found any Results. + */ + Standard_EXPORT static Standard_Integer GetInPlaceOld + (const TopoDS_Shape &theWhere, + const TopoDS_Shape &theWhat, + TopTools_ListOfShape &theShapesInPlace); + + + /** + * \brief GetInPlaceByHistory method implementation. + * Returns Standard_True if something is found. Warning: theShapesInPlace + * list is not cleared at first. + */ + Standard_EXPORT static Standard_Boolean GetInPlaceByHistory + (const Handle_GEOM_Function &theWhereFunction, + const TopTools_IndexedMapOfShape &theWhereIndices, + const TopoDS_Shape &theWhat, + TopTools_ListOfShape &theShapesInPlace); + +protected: + + /*! + * \brief Return normal to face at extrema point + */ + static gp_Vec GetNormal(const TopoDS_Face &theFace, + const BRepExtrema_DistShapeShape &theExtrema); + + /*! + * Return the global properties of the shape: center of mass and + * a size (length, area or volume depending on the shape type). + */ + static void GetShapeProperties(const TopoDS_Shape &theShape, + Standard_Real theTab[], + gp_Pnt &theVertex); + +}; + + + +#endif diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 8b6d59b49..43fa10a06 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -1351,6 +1351,10 @@ ICO_GET_SHARED_SHAPES shared_shapes.png + + ICO_TRANSFER_DATA + transfer_data.png + ICON_DLG_POINT_FACE pointonface.png @@ -1363,6 +1367,10 @@ ICON_DLG_SHARED_SHAPES shared_shapes.png + + ICON_DLG_TRANSFER_DATA + transfer_data.png + ICON_DLG_SCALE_ALONG_AXES scale_along_axes.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 8f7d8a97a..45b178e5e 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -5052,6 +5052,18 @@ Please, select face, shell or solid and try again STB_GET_SHARED_SHAPES Get shared shapes + + TOP_TRANSFER_DATA + Transfer Data + + + MEN_TRANSFER_DATA + Transfer Data + + + STB_TRANSFER_DATA + Transfer Data + TOP_EXTENSION Extend Edge or Face @@ -7184,4 +7196,59 @@ Do you want to create new material? SurfaceFromFace + + OperationGUI_TransferDataDlg + + GEOM_TRANSFER_DATA_TITLE + Transfer Data + + + GEOM_TRANSFER_DATA + Transfer Data + + + GEOM_TRANSFER_DATA_FROM + Source Shape + + + GEOM_TRANSFER_DATA_TO + Destination Shape + + + GEOM_TRANSFER_DATA_METHOD + Type of Detection Operation + + + GEOM_TD_METHOD_GETINPLACE + Get In Place + + + GEOM_TD_METHOD_GETINPLACE_OLD + Get In Place (old) + + + GEOM_TD_METHOD_GETINPLACE_HISTORY + Get In Place By History + + + 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 are copied: + + + GEOM_TRANSFER_DATA_NAMES + Names: %1 of %2 + + + GEOM_TRANSFER_DATA_MATERIALS + Materials: %1 of %2 + + diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index be77999a9..a8e6f6bca 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -602,6 +602,7 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpSharedShapes: // MENU OPERATION - GET SHARED SHAPES case GEOMOp::OpExtrudedBoss: // MENU OPERATION - EXTRUDED BOSS case GEOMOp::OpExtrudedCut: // MENU OPERATION - EXTRUDED CUT + case GEOMOp::OpTransferData: // MENU OPERATION - TRANSFER DATA libName = "OperationGUI"; break; case GEOMOp::OpSewing: // MENU REPAIR - SEWING @@ -971,6 +972,7 @@ void GeometryGUI::initialize( CAM_Application* app ) //createGeomAction( GEOMOp::OpClipping, "CLIPPING" ); createGeomAction( GEOMOp::OpShapesOnShape, "GET_SHAPES_ON_SHAPE" ); createGeomAction( GEOMOp::OpSharedShapes, "GET_SHARED_SHAPES" ); + createGeomAction( GEOMOp::OpTransferData, "TRANSFER_DATA" ); createGeomAction( GEOMOp::OpExtrudedCut, "EXTRUDED_CUT" ); createGeomAction( GEOMOp::OpExtrudedBoss, "EXTRUDED_BOSS" ); createGeomAction( GEOMOp::OpFillet1d, "FILLET_1D" ); @@ -1214,6 +1216,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpArchimede, operId, -1 ); createMenu( GEOMOp::OpShapesOnShape, operId, -1 ); createMenu( GEOMOp::OpSharedShapes, operId, -1 ); + createMenu( GEOMOp::OpTransferData, operId, -1 ); createMenu( separator(), operId, -1 ); @@ -1379,6 +1382,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( GEOMOp::OpArchimede, operTbId ); createTool( GEOMOp::OpShapesOnShape, operTbId ); createTool( GEOMOp::OpSharedShapes, operTbId ); + createTool( GEOMOp::OpTransferData, operTbId ); int featTbId = createTool( tr( "TOOL_FEATURES" ), QString( "GEOMModification" ) ); createTool( GEOMOp::OpFillet1d, featTbId ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 9a1e4fd40..7243340f4 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -157,6 +157,7 @@ namespace GEOMOp { OpSharedShapes = 3708, // MENU OPERATION - GET SHARED SHAPES OpExtrudedBoss = 3709, // MENU OPERATION - ETRUDED BOSS OpExtrudedCut = 3710, // MENU OPERATION - ETRUDED CUT + OpTransferData = 3711, // MENU OPERATION - TRANSFER DATA // RepairGUI -------------------//-------------------------------- OpSewing = 4000, // MENU REPAIR - SEWING OpSuppressFaces = 4001, // MENU REPAIR - SUPPRESS FACES diff --git a/src/GEOMImpl/CMakeLists.txt b/src/GEOMImpl/CMakeLists.txt index 42b467403..29436dabc 100755 --- a/src/GEOMImpl/CMakeLists.txt +++ b/src/GEOMImpl/CMakeLists.txt @@ -111,6 +111,7 @@ SET(GEOMImpl_HEADERS GEOMImpl_ICone.hxx GEOMImpl_ISphere.hxx GEOMImpl_ITorus.hxx + GEOMImpl_ITransferData.hxx GEOMImpl_IPrism.hxx GEOMImpl_IPipe.hxx GEOMImpl_IPipePath.hxx @@ -197,6 +198,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..427451f5e 100644 --- a/src/GEOMImpl/GEOMImpl_CopyDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_CopyDriver.cxx @@ -22,18 +22,29 @@ #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 "GEOMAlgo_GetInPlaceAPI.hxx" -#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 +76,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 +144,276 @@ 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; + TopTools_IndexedMapOfShape anIndices1; + + TopExp::MapShapes(aShape1, anIndices1); + + switch (aFindMethod) { + case TD_GET_IN_PLACE: + if (!getInPlace(aShape1, anIndices1, aShape2, aMapSoDest)) { + return 0; + } + break; + case TD_GET_IN_PLACE_OLD: + if (!getInPlaceOld(aRef1, anIndices1, aShape2, aMapSoDest)) { + return 0; + } + break; + case TD_GET_IN_PLACE_BY_HISTORY: + if (!getInPlaceByHistory(aRef1, anIndices1, aShape2, aRef2, aMapSoDest)) { + return 0; + } + break; + 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); + Standard_Integer i; + Standard_Integer aNbShapes = anIndices1.Extent(); + TopTools_MapOfShape aMapFence; + + 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(); + + if (aMapFence.Add(aShapeDest)) { + 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(); + + if (aMapFence.Add(aShapeDest)) { + aTD2.SetMaterial(aShapeDest, aMaterial); + } + } + } + } + } + + // Store results. + aTD.SetDatumName(aDatumName); + aTD.SetDatumMaxVal(aDatumMaxVal); + aTD.SetDatumVal(aDatumVal); + + return 1; +} + +//================================================================================ +/*! + * \brief For each subshape of the source shape compute coinsident sub-shapes + * of the destination shape using GetInPlace method. + */ +//================================================================================ + +Standard_Boolean GEOMImpl_CopyDriver::getInPlace + (const TopoDS_Shape &theSourceShape, + const TopTools_IndexedMapOfShape &theSourceIndices, + const TopoDS_Shape &theDestinationShape, + TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const +{ + // Searching for the sub-shapes inside theDestinationShape shape + GEOMAlgo_GetInPlace aGIP; + + if (!GEOMAlgo_GetInPlaceAPI::GetInPlace + (theDestinationShape, theSourceShape, aGIP)) { + return Standard_False; + } + + const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesIn = aGIP.ShapesIn(); + const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesOn = aGIP.ShapesOn(); + Standard_Integer i; + Standard_Integer j; + Standard_Integer aNbShapes = theSourceIndices.Extent(); + + for (i = 1; i <= aNbShapes; ++i) { + const TopoDS_Shape &aSource = theSourceIndices.FindKey(i); + TopTools_ListOfShape aListShapes2; + TopTools_MapOfShape aMapShapes2; + + for (j = 0; j < 2; ++j) { + const GEOMAlgo_DataMapOfShapeMapOfShape &aShapes2 = + j == 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()) { + theMapSourceDest.Add(aSource, aListShapes2); + } + } + + return Standard_True; +} + +//================================================================================ +/*! + * \brief For each subshape of the source shape compute coinsident sub-shapes + * of the destination shape using an old implementation + * of GetInPlace algorithm. + */ +//================================================================================ + +Standard_Boolean GEOMImpl_CopyDriver::getInPlaceOld + (const Handle(GEOM_Function) &theSourceRef, + const TopTools_IndexedMapOfShape &theSourceIndices, + const TopoDS_Shape &theDestinationShape, + TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const +{ + const Standard_Integer aNbShapes = theSourceIndices.Extent(); + Standard_Integer i; + Standard_Integer iErr; + TopTools_ListOfShape aModifiedList; + GEOMImpl_ITransferData aTDSource(theSourceRef); + + for (i = 1; i <= aNbShapes; ++i) { + const TopoDS_Shape &aSource = theSourceIndices.FindKey(i); + TCollection_AsciiString aName = aTDSource.GetName(aSource); + TCollection_AsciiString aMaterial = aTDSource.GetMaterial(aSource); + + if (aName.IsEmpty() && aMaterial.IsEmpty()) { + continue; + } + + // Call old GetInPlace. + iErr = GEOMAlgo_GetInPlaceAPI::GetInPlaceOld + (theDestinationShape, aSource, aModifiedList); + + if (iErr == 3) { + // Nothing is found. Skip. + continue; + } + + if (iErr) { + // Error. + return Standard_False; + } + + theMapSourceDest.Add(aSource, aModifiedList); + } + + return Standard_True; +} + +//================================================================================ +/*! + * \brief For each subshape of the source shape compute coinsident sub-shapes + * of the destination shape using GetInPlaceByHistory algorithm. + */ +//================================================================================ + +Standard_Boolean GEOMImpl_CopyDriver::getInPlaceByHistory + (const Handle(GEOM_Function) &theSourceRef, + const TopTools_IndexedMapOfShape &theSourceIndices, + const TopoDS_Shape &theDestinationShape, + const Handle(GEOM_Function) &theDestinationRef, + TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const +{ + const Standard_Integer aNbShapes = theSourceIndices.Extent(); + Standard_Integer i; + GEOMImpl_ITransferData aTDSource(theSourceRef); + TopTools_IndexedMapOfShape aDestIndices; + + TopExp::MapShapes(theDestinationShape, aDestIndices); + + for (i = 1; i <= aNbShapes; ++i) { + const TopoDS_Shape &aSource = theSourceIndices.FindKey(i); + TCollection_AsciiString aName = aTDSource.GetName(aSource); + TCollection_AsciiString aMaterial = aTDSource.GetMaterial(aSource); + + if (aName.IsEmpty() && aMaterial.IsEmpty()) { + continue; + } + + // Call GetInPlaceByHistory. + TopTools_ListOfShape aModifiedList; + const Standard_Boolean isFound = GEOMAlgo_GetInPlaceAPI::GetInPlaceByHistory + (theDestinationRef, aDestIndices, aSource, aModifiedList); + + if (isFound && !aModifiedList.IsEmpty()) { + theMapSourceDest.Add(aSource, aModifiedList); + } + } + + return Standard_True; +} + 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..602bc2ddc 100644 --- a/src/GEOMImpl/GEOMImpl_CopyDriver.hxx +++ b/src/GEOMImpl/GEOMImpl_CopyDriver.hxx @@ -26,42 +26,15 @@ #ifndef _GEOMImpl_CopyDriver_HeaderFile #define _GEOMImpl_CopyDriver_HeaderFile -#ifndef _TColStd_SequenceOfExtendedString_HeaderFile -#include -#endif -#ifndef _Standard_TypeMismatch_HeaderFile -#include -#endif - -#ifndef _Standard_HeaderFile -#include -#endif - -#ifndef _Standard_Macro_HeaderFile -#include -#endif -#ifndef _Standard_HeaderFile -#include -#endif -#ifndef _Standard_GUID_HeaderFile -#include -#endif - -#ifndef _TFunction_Driver_HeaderFile -#include -#endif -#ifndef _TFunction_Logbook_HeaderFile -#include -#endif -#ifndef _Standard_CString_HeaderFile -#include -#endif - -class TColStd_SequenceOfExtendedString; +class TopoDS_Shape; +class TopTools_IndexedDataMapOfShapeListOfShape; +class TopTools_IndexedMapOfShape; +class Standard_GUID; #include "GEOM_BaseDriver.hxx" + DEFINE_STANDARD_HANDLE( GEOMImpl_CopyDriver, GEOM_BaseDriver ); class GEOMImpl_CopyDriver : public GEOM_BaseDriver { @@ -82,6 +55,30 @@ Standard_EXPORT ~GEOMImpl_CopyDriver() {}; std::vector& params); DEFINE_STANDARD_RTTI( GEOMImpl_CopyDriver ) + +private: + + Standard_Integer transferData(TFunction_Logbook& log) const; + + Standard_Boolean getInPlace + (const TopoDS_Shape &theSourceShape, + const TopTools_IndexedMapOfShape &theSourceIndices, + const TopoDS_Shape &theDestinationShape, + TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const; + + Standard_Boolean getInPlaceOld + (const Handle(GEOM_Function) &theSourceShapeRef, + const TopTools_IndexedMapOfShape &theSourceIndices, + const TopoDS_Shape &theDestinationShape, + TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const; + + Standard_Boolean getInPlaceByHistory + (const Handle(GEOM_Function) &theSourceShapeRef, + const TopTools_IndexedMapOfShape &theSourceIndices, + const TopoDS_Shape &theDestinationShape, + const Handle(GEOM_Function) &theDestinationRef, + TopTools_IndexedDataMapOfShapeListOfShape &theMapSourceDest) const; + }; #endif diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx old mode 100755 new mode 100644 index e5f5a1f94..047b17ac1 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "GEOMImpl_IShapesOperations.hxx" #include "GEOMImpl_IGroupOperations.hxx" @@ -340,3 +341,107 @@ std::list GEOMImpl_IInsertOperations::GetAllTextures() SetErrorCode(OK); return id_list; } + +//============================================================================= +/*! + * TransferData + */ +//============================================================================= +bool GEOMImpl_IInsertOperations::TransferData + (const Handle(GEOM_Object) &theObjectFrom, + const Handle(GEOM_Object) &theObjectTo, + const int theFindMethod, + std::list &theResult) +{ + SetErrorCode(KO); + + if (theObjectFrom.IsNull() || theObjectTo.IsNull()) { + return false; + } + + //Add a new Transfer Data object object + Handle(GEOM_Object) aTDObj = + GetEngine()->AddObject(GetDocID(), GEOM_TRANSFER_DATA); + + //Add a Transfer Data function for created object + Handle(GEOM_Function) aFunction = + aTDObj->AddFunction(GEOMImpl_CopyDriver::GetID(), TRANSFER_DATA); + + //Check if the function is set correctly + if(aFunction->GetDriverGUID() != GEOMImpl_CopyDriver::GetID()) { + return false; + } + + Handle(GEOM_Function) aFunctionFrom = theObjectFrom->GetLastFunction(); + Handle(GEOM_Function) aFunctionTo = theObjectTo->GetLastFunction(); + + if (aFunctionFrom.IsNull() || aFunctionTo.IsNull()) { + return false; + } + + GEOMImpl_ITransferData aTD(aFunction); + + aTD.SetRef1(aFunctionFrom); + aTD.SetRef2(aFunctionTo); + aTD.SetFindMethod(theFindMethod); + + // Transfer data + try { + OCC_CATCH_SIGNALS; + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Transfer data failed"); + return false; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + 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; + pd << ", GEOM."; + + switch (theFindMethod) { + case TD_GET_IN_PLACE: + pd << "FSM_GetInPlace"; + break; + case TD_GET_IN_PLACE_OLD: + pd << "FSM_GetInPlace_Old"; + break; + case TD_GET_IN_PLACE_BY_HISTORY: + default: + pd << "FSM_GetInPlaceByHistory"; + break; + } + pd << ")"; + + SetErrorCode(OK); + + return true; +} diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx index 9341c2b8d..f9694ea4e 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx @@ -49,6 +49,14 @@ class Handle_TColStd_HArray1OfByte; class GEOMImpl_IInsertOperations : public GEOM_IOperations { public: + + struct TransferDatum + { + TCollection_AsciiString myName; + long myNumber; + long myMaxNumber; + }; + Standard_EXPORT GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID); Standard_EXPORT ~GEOMImpl_IInsertOperations(); @@ -79,6 +87,12 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations { Standard_EXPORT std::list GetAllTextures(); + Standard_EXPORT bool TransferData + (const Handle(GEOM_Object) &theObjectFrom, + const Handle(GEOM_Object) &theObjectTo, + const int theFindMethod, + std::list &theResult); + private: std::vector myResMgrList; GEOMImpl_IShapesOperations* myShapesOperations; diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index 1a7c43205..fec403a59 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -25,7 +25,7 @@ // Author : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007 // Project : SALOME -#include +//#include #include "GEOMImpl_IShapesOperations.hxx" @@ -55,62 +55,32 @@ #include "GEOMAlgo_ClsfBox.hxx" #include "GEOMAlgo_ClsfSolid.hxx" -#include "GEOMAlgo_CoupleOfShapes.hxx" #include "GEOMAlgo_FinderShapeOn1.hxx" #include "GEOMAlgo_FinderShapeOnQuad.hxx" #include "GEOMAlgo_FinderShapeOn2.hxx" #include "GEOMAlgo_GetInPlace.hxx" +#include "GEOMAlgo_GetInPlaceAPI.hxx" #include "GEOMAlgo_GlueDetector.hxx" -#include "GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx" -#include "GEOMAlgo_ListOfCoupleOfShapes.hxx" - -#include #include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include -#include -#include -#include -#include #include #include #include #include #include #include -#include #include -#include -#include #include #include -#include #include -#include -#include -#include -#include #include #include -#include -#include #include #include #include @@ -126,59 +96,15 @@ #include #include #include -#include #include #include -#include -#include -#include #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC namespace { - //================================================================================ - /*! - * \brief Return normal to face at extrema point - */ - //================================================================================ - - gp_Vec GetNormal (const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema) - { - gp_Vec defaultNorm(1,0,0); // to have same normals on different faces - try { - // get UV at extrema point - Standard_Real u,v, f,l; - switch ( extrema.SupportTypeShape2(1) ) { - case BRepExtrema_IsInFace: { - extrema.ParOnFaceS2(1, u, v ); - break; - } - case BRepExtrema_IsOnEdge: { - TopoDS_Edge edge = TopoDS::Edge( extrema.SupportOnShape2(1)); - Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( edge, face, f,l ); - extrema.ParOnEdgeS2( 1, u ); - gp_Pnt2d uv = pcurve->Value( u ); - u = uv.Coord(1); - v = uv.Coord(2); - break; - } - case BRepExtrema_IsVertex: return defaultNorm; - } - // get derivatives - BRepAdaptor_Surface surface( face, false ); - gp_Vec du, dv; gp_Pnt p; - surface.D1( u, v, p, du, dv ); - - return du ^ dv; - - } catch (Standard_Failure ) { - } - return defaultNorm; - } - void AddFlatSubShapes(const TopoDS_Shape& S, TopTools_ListOfShape& L, TopTools_MapOfShape& M) { if (S.ShapeType() != TopAbs_COMPOUND) { @@ -3966,165 +3892,6 @@ Handle(TColStd_HSequenceOfInteger) return aSeqOfIDs; } -//============================================================================= -/*! - * GetInPlaceOfShape - */ -//============================================================================= -static bool GetInPlaceOfShape (const Handle(GEOM_Function)& theWhereFunction, - const TopTools_IndexedMapOfShape& theWhereIndices, - const TopoDS_Shape& theWhat, - TColStd_ListOfInteger& theModifiedList) -{ - if (theWhereFunction.IsNull() || theWhat.IsNull()) return false; - - if (theWhereIndices.Contains(theWhat)) { - // entity was not changed by the operation - Standard_Integer aWhatIndex = theWhereIndices.FindIndex(theWhat); - theModifiedList.Append(aWhatIndex); - return true; - } - - // try to find in history - TDF_Label aHistoryLabel = theWhereFunction->GetHistoryEntry(Standard_False); - - // search in history for all argument shapes - Standard_Boolean isFound = Standard_False; - Standard_Boolean isGood = Standard_False; - - TDF_LabelSequence aLabelSeq; - theWhereFunction->GetDependency(aLabelSeq); - Standard_Integer nbArg = aLabelSeq.Length(); - - for (Standard_Integer iarg = 1; iarg <= nbArg && !isFound; iarg++) { - - TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg); - - Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel); - TopoDS_Shape anArgumentShape = anArgumentObject->GetValue(); - - TopTools_IndexedMapOfShape anArgumentIndices; - TopExp::MapShapes(anArgumentShape, anArgumentIndices); - - if (anArgumentIndices.Contains(theWhat)) { - isFound = Standard_True; - Standard_Integer aWhatIndex = anArgumentIndices.FindIndex(theWhat); - - // Find corresponding label in history - TDF_Label anArgumentHistoryLabel = - theWhereFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_False); - if (anArgumentHistoryLabel.IsNull()) { - // Lost History of operation argument. Possibly, all its entities was removed. - isGood = Standard_True; - } - else { - TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(aWhatIndex, Standard_False); - - if (aWhatHistoryLabel.IsNull()) { - // Removed entity ? Compound ? Compsolid ? Shell ? Wire - isGood = Standard_False; - } else { - Handle(TDataStd_IntegerArray) anIntegerArray; - if (!aWhatHistoryLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) { - //Error: Empty modifications history for the sought shape. - isGood = Standard_False; - } - else { - isGood = Standard_True; - Standard_Integer imod, aModifLen = anIntegerArray->Array()->Length(); - for (imod = 1; imod <= aModifLen; imod++) { - theModifiedList.Append(anIntegerArray->Array()->Value(imod)); - } - } - } - } - } - } - - isFound = isGood; - - if (!isFound) { - // try compound/compsolid/shell/wire element by element - bool isFoundAny = false; - TopTools_MapOfShape mapShape; - - if (theWhat.ShapeType() == TopAbs_COMPOUND || - theWhat.ShapeType() == TopAbs_COMPSOLID) { - // recursive processing of compound/compsolid - TopoDS_Iterator anIt (theWhat, Standard_True, Standard_True); - for (; anIt.More(); anIt.Next()) { - if (mapShape.Add(anIt.Value())) { - TopoDS_Shape curWhat = anIt.Value(); - isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList); - if (isFoundAny) isFound = Standard_True; - } - } - } - else if (theWhat.ShapeType() == TopAbs_SHELL) { - // try to replace a shell by its faces images - TopExp_Explorer anExp (theWhat, TopAbs_FACE); - for (; anExp.More(); anExp.Next()) { - if (mapShape.Add(anExp.Current())) { - TopoDS_Shape curWhat = anExp.Current(); - isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList); - if (isFoundAny) isFound = Standard_True; - } - } - } - else if (theWhat.ShapeType() == TopAbs_WIRE) { - // try to replace a wire by its edges images - TopExp_Explorer anExp (theWhat, TopAbs_EDGE); - for (; anExp.More(); anExp.Next()) { - if (mapShape.Add(anExp.Current())) { - TopoDS_Shape curWhat = anExp.Current(); - isFoundAny = GetInPlaceOfShape(theWhereFunction, theWhereIndices, curWhat, theModifiedList); - if (isFoundAny) isFound = Standard_True; - } - } - } - else { - // Removed entity - } - } - - return isFound; -} - -//============================================================================= -/*! - * GetShapeProperties - */ -//============================================================================= -void GEOMImpl_IShapesOperations::GetShapeProperties( const TopoDS_Shape aShape, Standard_Real tab[], - gp_Pnt & aVertex ) -{ - GProp_GProps theProps; - gp_Pnt aCenterMass; - //TopoDS_Shape aPntShape; - Standard_Real aShapeSize; - - if (aShape.ShapeType() == TopAbs_VERTEX) aCenterMass = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) ); - else if (aShape.ShapeType() == TopAbs_EDGE) BRepGProp::LinearProperties(aShape, theProps); - else if (aShape.ShapeType() == TopAbs_FACE) BRepGProp::SurfaceProperties(aShape, theProps); - else BRepGProp::VolumeProperties(aShape, theProps); - - if (aShape.ShapeType() == TopAbs_VERTEX) - aShapeSize = 1; - else { - aCenterMass = theProps.CentreOfMass(); - aShapeSize = theProps.Mass(); - } - -// aPntShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape(); -// aVertex = BRep_Tool::Pnt( TopoDS::Vertex( aPntShape ) ); - aVertex = aCenterMass; - tab[0] = aVertex.X(); - tab[1] = aVertex.Y(); - tab[2] = aVertex.Z(); - tab[3] = aShapeSize; - return; -} - //============================================================================= /*! * case GetInPlace: @@ -4146,47 +3913,10 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) return NULL; } - // Compute confusion tolerance. - Standard_Real aTolConf = Precision::Confusion(); - Standard_Integer i; - - for (i = 0; i < 2; ++i) { - TopExp_Explorer anExp(i == 0 ? aWhere : aWhat, 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(aWhere, aBoundingBox); - BRepBndLib::Add(aWhat, 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(aWhat); - aGIP.SetShapeWhere(aWhere); - - aGIP.Perform(); - int iErr = aGIP.ErrorStatus(); - if (iErr) { + if (!GEOMAlgo_GetInPlaceAPI::GetInPlace(aWhere, aWhat, aGIP)) { SetErrorCode("Error in GEOMAlgo_GetInPlace"); return NULL; } @@ -4263,201 +3993,59 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) * default: */ //============================================================================= -Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceOld (Handle(GEOM_Object) theShapeWhere, - Handle(GEOM_Object) theShapeWhat) +Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceOld + (Handle(GEOM_Object) theShapeWhere, + Handle(GEOM_Object) theShapeWhat) { SetErrorCode(KO); if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL; - TopoDS_Shape aWhere = theShapeWhere->GetValue(); - TopoDS_Shape aWhat = theShapeWhat->GetValue(); - TopoDS_Shape aPntShape; - TopoDS_Vertex aVertex; + TopoDS_Shape aWhere = theShapeWhere->GetValue(); + TopoDS_Shape aWhat = theShapeWhat->GetValue(); + TopTools_ListOfShape aModifiedList; + const Standard_Integer iErr = + GEOMAlgo_GetInPlaceAPI::GetInPlaceOld(aWhere, aWhat, aModifiedList); - if (aWhere.IsNull() || aWhat.IsNull()) { - SetErrorCode("Error: aWhere and aWhat TopoDS_Shape are Null."); - return NULL; - } + if (iErr) { + switch (iErr) { + case 1: + SetErrorCode("Error: aWhere and aWhat TopoDS_Shape are Null."); + break; + case 2: + SetErrorCode + ("Error: An attempt to extract a shape of not supported type."); + break; + case 3: + SetErrorCode(NOT_FOUND_ANY); + break; + default: + SetErrorCode("Shape driver failed"); + break; + } - Handle(GEOM_Function) aWhereFunction = theShapeWhere->GetLastFunction(); - if (aWhereFunction.IsNull()) { - SetErrorCode("Error: aWhereFunction is Null."); return NULL; } TopTools_IndexedMapOfShape aWhereIndices; TopExp::MapShapes(aWhere, aWhereIndices); - TColStd_ListOfInteger aModifiedList; - Standard_Integer aWhereIndex; - Handle(TColStd_HArray1OfInteger) aModifiedArray; - Handle(GEOM_Object) aResult; + Handle(TColStd_HArray1OfInteger) aModifiedArray = + new TColStd_HArray1OfInteger (1, aModifiedList.Extent()); + TopTools_ListIteratorOfListOfShape anIterModif (aModifiedList); + Standard_Integer imod; - bool isFound = false; - TopAbs_ShapeEnum iType = TopAbs_SOLID; - //Standard_Real aWhat_Mass = 0., aWhere_Mass = 0.; - Standard_Real tab_aWhat[4], tab_aWhere[4]; - Standard_Real dl_l = 1e-3; - Standard_Real min_l, Tol_0D, Tol_1D, Tol_2D, Tol_3D, Tol_Mass; - Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; - Bnd_Box BoundingBox; - gp_Pnt aPnt, aPnt_aWhat, tab_Pnt[2]; - GProp_GProps aProps; + for (imod = 1; anIterModif.More(); anIterModif.Next(), imod++) { + const Standard_Integer anIndex = + aWhereIndices.FindIndex(anIterModif.Value()); - // Find the iType of the aWhat shape - /* - if ( aWhat.ShapeType() == TopAbs_VERTEX ) iType = TopAbs_VERTEX; - else if ( aWhat.ShapeType() == TopAbs_EDGE || aWhat.ShapeType() == TopAbs_WIRE ) iType = TopAbs_EDGE; - else if ( aWhat.ShapeType() == TopAbs_FACE || aWhat.ShapeType() == TopAbs_SHELL ) iType = TopAbs_FACE; - else if ( aWhat.ShapeType() == TopAbs_SOLID || aWhat.ShapeType() == TopAbs_COMPSOLID ) iType = TopAbs_SOLID; - else if ( aWhat.ShapeType() == TopAbs_COMPOUND ) { - // Only the iType of the first shape in the compound is taken into account - TopoDS_Iterator It (aWhat, Standard_False, Standard_False); - if ( !It.More() ) { - SetErrorCode("Error: theShapeWhat is an empty COMPOUND."); - return NULL; - } - TopAbs_ShapeEnum compType = It.Value().ShapeType(); - if ( compType == TopAbs_VERTEX ) iType = TopAbs_VERTEX; - else if ( compType == TopAbs_EDGE || compType == TopAbs_WIRE ) iType = TopAbs_EDGE; - else if ( compType == TopAbs_FACE || compType == TopAbs_SHELL) iType = TopAbs_FACE; - else if ( compType == TopAbs_SOLID || compType == TopAbs_COMPSOLID) iType = TopAbs_SOLID; + aModifiedArray->SetValue(imod, anIndex); } - else { - SetErrorCode("Error: An attempt to extract a shape of not supported type."); - return NULL; - } - */ - iType = GEOMUtils::GetTypeOfSimplePart(aWhat); - if (iType == TopAbs_SHAPE) { - SetErrorCode("Error: An attempt to extract a shape of not supported type."); - return NULL; - } - - TopExp_Explorer Exp_aWhat ( aWhat, iType ); - TopExp_Explorer Exp_aWhere ( aWhere, iType ); - TopExp_Explorer Exp_Edge ( aWhere, TopAbs_EDGE ); - - // Find the shortest edge in theShapeWhere shape - BRepBndLib::Add(aWhere, BoundingBox); - BoundingBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); - min_l = fabs(aXmax - aXmin); - if( min_l < fabs(aYmax - aYmin) ) min_l = fabs(aYmax - aYmin); - if( min_l < fabs(aZmax - aZmin) ) min_l = fabs(aZmax - aZmin); - min_l /= dl_l; - // Mantis issue 0020908 BEGIN - if (!Exp_Edge.More()) { - min_l = Precision::Confusion(); - } - // Mantis issue 0020908 END - for ( Standard_Integer nbEdge = 0; Exp_Edge.More(); Exp_Edge.Next(), nbEdge++ ) { - TopExp_Explorer Exp_Vertex( Exp_Edge.Current(), TopAbs_VERTEX); - for ( Standard_Integer nbVertex = 0; Exp_Vertex.More(); Exp_Vertex.Next(), nbVertex++ ) { - aPnt = BRep_Tool::Pnt( TopoDS::Vertex( Exp_Vertex.Current() ) ); - tab_Pnt[nbVertex] = aPnt; - } - if ( ! tab_Pnt[0].IsEqual(tab_Pnt[1], dl_l) ) { - BRepGProp::LinearProperties(Exp_Edge.Current(), aProps); - if ( aProps.Mass() < min_l ) min_l = aProps.Mass(); - } - } - - // Compute tolerances - Tol_0D = dl_l; - Tol_1D = dl_l * min_l; - Tol_2D = dl_l * ( min_l * min_l) * ( 2. + dl_l); - Tol_3D = dl_l * ( min_l * min_l * min_l ) * ( 3. + (3 * dl_l) + (dl_l * dl_l) ); - - if (Tol_0D < Precision::Confusion()) Tol_0D = Precision::Confusion(); - if (Tol_1D < Precision::Confusion()) Tol_1D = Precision::Confusion(); - if (Tol_2D < Precision::Confusion()) Tol_2D = Precision::Confusion(); - if (Tol_3D < Precision::Confusion()) Tol_3D = Precision::Confusion(); - - //if (Tol_1D > 1.0) Tol_1D = 1.0; - //if (Tol_2D > 1.0) Tol_2D = 1.0; - //if (Tol_3D > 1.0) Tol_3D = 1.0; - - Tol_Mass = Tol_3D; - if ( iType == TopAbs_VERTEX ) Tol_Mass = Tol_0D; - else if ( iType == TopAbs_EDGE ) Tol_Mass = Tol_1D; - else if ( iType == TopAbs_FACE ) Tol_Mass = Tol_2D; - - // Compute the ShapeWhat Mass - /* - for ( ; Exp_aWhat.More(); Exp_aWhat.Next() ) { - if ( iType == TopAbs_VERTEX ) { - aWhat_Mass += 1; - continue; - } - else if ( iType == TopAbs_EDGE ) BRepGProp::LinearProperties(Exp_aWhat.Current(), aProps); - else if ( iType == TopAbs_FACE ) BRepGProp::SurfaceProperties(Exp_aWhat.Current(), aProps); - else BRepGProp::VolumeProperties(Exp_aWhat.Current(), aProps); - aWhat_Mass += aProps.Mass(); - } - */ - - // Searching for the sub-shapes inside the ShapeWhere shape - TopTools_MapOfShape map_aWhere; - for ( Exp_aWhere.ReInit(); Exp_aWhere.More(); Exp_aWhere.Next() ) { - if (!map_aWhere.Add(Exp_aWhere.Current())) - continue; // skip repeated shape to avoid mass addition - GetShapeProperties( Exp_aWhere.Current(), tab_aWhere, aPnt ); - for ( Exp_aWhat.ReInit(); Exp_aWhat.More(); Exp_aWhat.Next() ) { - GetShapeProperties( Exp_aWhat.Current(), tab_aWhat, aPnt_aWhat ); - if ( fabs(tab_aWhat[3] - tab_aWhere[3]) <= Tol_Mass && aPnt_aWhat.Distance(aPnt) <= Tol_1D ) - isFound = true; - else { - if ( (tab_aWhat[3] - tab_aWhere[3]) > Tol_Mass ) { - aPntShape = BRepBuilderAPI_MakeVertex( aPnt ).Shape(); - aVertex = TopoDS::Vertex( aPntShape ); - BRepExtrema_DistShapeShape aWhereDistance ( aVertex, Exp_aWhere.Current() ); - BRepExtrema_DistShapeShape aWhatDistance ( aVertex, Exp_aWhat.Current() ); - if ( aWhereDistance.IsDone() && aWhatDistance.IsDone() && - fabs(aWhereDistance.Value() - aWhatDistance.Value()) <= Tol_1D ) - { - // 0020162: "EDF 961 GEOM : Getinplace is getting additionnal orthogonal faces" - // aVertex must be projected to the same point on Where and on What - gp_Pnt pOnWhat = aWhatDistance.PointOnShape2(1); - gp_Pnt pOnWhere = aWhereDistance.PointOnShape2(1); - isFound = ( pOnWhat.Distance(pOnWhere) <= Tol_1D ); - if ( isFound && iType == TopAbs_FACE ) - { - // check normals at pOnWhat and pOnWhere - const double angleTol = M_PI/180.; - gp_Vec normToWhat = GetNormal( TopoDS::Face(Exp_aWhat.Current()), aWhatDistance); - gp_Vec normToWhere = GetNormal( TopoDS::Face(Exp_aWhere.Current()), aWhereDistance); - if ( normToWhat * normToWhere < 0 ) - normToWhat.Reverse(); - isFound = ( normToWhat.Angle( normToWhere ) < angleTol ); - } - } - } - } - if ( isFound ) { - aWhereIndex = aWhereIndices.FindIndex(Exp_aWhere.Current()); - aModifiedList.Append(aWhereIndex); - //aWhere_Mass += tab_aWhere[3]; - isFound = false; - break; - } - } - //if ( fabs( aWhat_Mass - aWhere_Mass ) <= Tol_Mass ) - //break; - } - - if (aModifiedList.Extent() == 0) { // Not found any Results - SetErrorCode(NOT_FOUND_ANY); - return NULL; - } - - aModifiedArray = new TColStd_HArray1OfInteger (1, aModifiedList.Extent()); - TColStd_ListIteratorOfListOfInteger anIterModif (aModifiedList); - for (Standard_Integer imod = 1; anIterModif.More(); anIterModif.Next(), imod++) - aModifiedArray->SetValue(imod, anIterModif.Value()); //Add a new object - aResult = GetEngine()->AddSubShape(theShapeWhere, aModifiedArray); + Handle(GEOM_Object) aResult = + GetEngine()->AddSubShape(theShapeWhere, aModifiedArray); + if (aResult.IsNull()) { SetErrorCode("Error in algorithm: result found, but cannot be returned."); return NULL; @@ -4482,6 +4070,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceOld (Handle(GEOM_Objec << theShapeWhere << ", " << theShapeWhat << ", False)"; SetErrorCode(OK); + return aResult; } @@ -4507,11 +4096,13 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceByHistory //Fill array of indices TopTools_IndexedMapOfShape aWhereIndices; + TopExp::MapShapes(aWhere, aWhereIndices); // process shape - TColStd_ListOfInteger aModifiedList; - bool isFound = GetInPlaceOfShape(aWhereFunction, aWhereIndices, aWhat, aModifiedList); + TopTools_ListOfShape aModifiedList; + bool isFound = GEOMAlgo_GetInPlaceAPI::GetInPlaceByHistory + (aWhereFunction, aWhereIndices, aWhat, aModifiedList); if (!isFound || aModifiedList.Extent() < 1) { SetErrorCode("Error: No history found for the sought shape or its sub-shapes."); @@ -4519,13 +4110,13 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceByHistory } Standard_Integer nbFound = aModifiedList.Extent(); - TColStd_ListIteratorOfListOfInteger anIterModif (aModifiedList); + TopTools_ListIteratorOfListOfShape anIterModif (aModifiedList); if ( nbFound > 1 ) { // remove sub-shapes inappropriate for group creation TopAbs_ShapeEnum subType = TopAbs_SHAPE; while ( anIterModif.More() ) { - TopAbs_ShapeEnum type = aWhereIndices( anIterModif.Value() ).ShapeType(); + TopAbs_ShapeEnum type = anIterModif.Value().ShapeType(); bool okForGroup = ( type == TopAbs_VERTEX || type == TopAbs_EDGE || type == TopAbs_FACE || type == TopAbs_SOLID ); if ( okForGroup ) { @@ -4550,7 +4141,8 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlaceByHistory new TColStd_HArray1OfInteger( 1, nbFound ); anIterModif.Initialize(aModifiedList); for (Standard_Integer imod = 1; anIterModif.More(); anIterModif.Next(), imod++) - aModifiedArray->SetValue(imod, anIterModif.Value()); + aModifiedArray->SetValue + (imod, aWhereIndices.FindIndex(anIterModif.Value())); //Add a new object Handle(GEOM_Object) aResult = GetEngine()->AddSubShape(theShapeWhere, aModifiedArray); diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index 06b35dac4..d1827ee9c 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -34,22 +34,17 @@ #include "GEOMAlgo_State.hxx" -#include -#include -#include #include #include -#include - -#include +#include #include -#include class GEOM_Engine; class Handle(GEOM_Object); class Handle(TColStd_HArray1OfInteger); +class TopoDS_Shape; class GEOMImpl_IShapesOperations : public GEOM_IOperations { @@ -304,8 +299,6 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations Handle(GEOM_Object) theCenter, const Standard_Real theRadius); - void GetShapeProperties(const TopoDS_Shape aShape, Standard_Real propertiesArray[], gp_Pnt & aPnt); - Standard_EXPORT Handle(GEOM_Object) GetInPlace (Handle(GEOM_Object) theShapeWhere, Handle(GEOM_Object) theShapeWhat); 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 new file mode 100644 index 000000000..761ed19e2 --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_ITransferData.hxx @@ -0,0 +1,114 @@ +// 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. +// + + +#ifndef _GEOMImpl_ITransferData_HXX_ +#define _GEOMImpl_ITransferData_HXX_ + + +#include "GEOM_GEOMImpl.hxx" +#include "GEOM_Function.hxx" + +#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 +{ + public: + + GEOMImpl_ITransferData(const Handle(GEOM_Function) &theFunction) + : _func(theFunction) {} + + void SetRef1(const Handle(GEOM_Function) &theRefPoint1) + { _func->SetReference(TD_ARG_REF1, theRefPoint1); } + + Handle(GEOM_Function) GetRef1() { return _func->GetReference(TD_ARG_REF1); } + + void SetRef2(const Handle(GEOM_Function) &theRefPoint2) + { _func->SetReference(TD_ARG_REF2, theRefPoint2); } + + Handle(GEOM_Function) GetRef2() { return _func->GetReference(TD_ARG_REF2); } + + void SetFindMethod(const int theFindMethod) + { _func->SetInteger(TD_ARG_METHOD, theFindMethod); } + + 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/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 272db63b8..073a6c778 100644 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -117,10 +117,13 @@ #define GEOM_POLYLINE2D 56 +#define GEOM_TRANSFER_DATA 57 + //GEOM_Function types #define COPY_WITH_REF 1 #define COPY_WITHOUT_REF 2 +#define TRANSFER_DATA 3 #define IMPORT_SHAPE 1 #define EXPORT_SHAPE 2 @@ -379,6 +382,10 @@ #define USER_TYPE 200 // Base type for GEOM advanced shapes #define USER_TYPE_EX 1000 // Base type for GEOM plugins +// Transfer data method type +#define TD_GET_IN_PLACE 1 +#define TD_GET_IN_PLACE_OLD 2 +#define TD_GET_IN_PLACE_BY_HISTORY 3 // Plugins specified constants #define PLUGIN_NAME "Plugin Name" diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.cc b/src/GEOM_I/GEOM_IInsertOperations_i.cc index ab79c87b6..334000f23 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.cc +++ b/src/GEOM_I/GEOM_IInsertOperations_i.cc @@ -34,6 +34,7 @@ #include "GEOM_Engine.hxx" #include "GEOM_BaseObject.hxx" +#include "GEOMImpl_Types.hxx" #include @@ -259,4 +260,83 @@ GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures() return anIDs._retn(); } +//============================================================================= +/*! + * TransferData + */ +//============================================================================= +CORBA::Boolean GEOM_IInsertOperations_i::TransferData + (GEOM::GEOM_Object_ptr theObjectFrom, + GEOM::GEOM_Object_ptr theObjectTo, + GEOM::find_shape_method theFindMethod, + GEOM::GEOM_IInsertOperations::ListOfTransferDatum_out theResult) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + if (CORBA::is_nil(theObjectFrom) || CORBA::is_nil(theObjectTo)) + { + return false; + } + + //Get the reference shape + Handle(GEOM_Object) aShapeFrom = GetObjectImpl(theObjectFrom); + Handle(GEOM_Object) aShapeTo = GetObjectImpl(theObjectTo); + + if (aShapeFrom.IsNull() || aShapeTo.IsNull()) + { + return false; + } + + bool isOk = false; + std::list aData; + int aFindMethod = -1; + + switch (theFindMethod) { + case GEOM::FSM_GetInPlace: + aFindMethod = TD_GET_IN_PLACE; + break; + case GEOM::FSM_GetInPlaceByHistory: + aFindMethod = TD_GET_IN_PLACE_BY_HISTORY; + break; + case GEOM::FSM_GetInPlace_Old: + aFindMethod = TD_GET_IN_PLACE_OLD; + break; + default: + break; + } + + // Transfer data. + if (aFindMethod > 0) { + isOk = GetOperations()->TransferData + (aShapeFrom, aShapeTo, aFindMethod, aData); + } + + if (isOk) { + // Copy results. + const int aNbDatum = aData.size(); + GEOM::GEOM_IInsertOperations::ListOfTransferDatum_var aResult = + new GEOM::GEOM_IInsertOperations::ListOfTransferDatum; + + aResult->length(aNbDatum); + + // fill the local CORBA array with values from lists + std::list::const_iterator + anIt = aData.begin(); + int i = 0; + + for (; anIt != aData.end(); i++, anIt++) { + GEOM::GEOM_IInsertOperations::TransferDatum_var aDatum = + new GEOM::GEOM_IInsertOperations::TransferDatum; + + aDatum->myName = CORBA::string_dup(anIt->myName.ToCString()); + aDatum->myNumber = anIt->myNumber; + aDatum->myMaxNumber = anIt->myMaxNumber; + aResult[i] = aDatum; + } + + theResult = aResult._retn(); + } + + return isOk; +} diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.hh b/src/GEOM_I/GEOM_IInsertOperations_i.hh index 4a2b4f2cc..26bfa4d88 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.hh +++ b/src/GEOM_I/GEOM_IInsertOperations_i.hh @@ -66,7 +66,13 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i : CORBA::Long& theHeight); GEOM::ListOfLong* GetAllTextures(); - + + CORBA::Boolean TransferData + (GEOM::GEOM_Object_ptr theObjectFrom, + GEOM::GEOM_Object_ptr theObjectTo, + GEOM::find_shape_method theFindMethod, + GEOM::GEOM_IInsertOperations::ListOfTransferDatum_out theResult); + ::GEOMImpl_IInsertOperations* GetOperations() { return (::GEOMImpl_IInsertOperations*)GetImpl(); } }; diff --git a/src/GEOM_SWIG/GEOM_TestOthers.py b/src/GEOM_SWIG/GEOM_TestOthers.py index 2cb39a2bf..548204a65 100644 --- a/src/GEOM_SWIG/GEOM_TestOthers.py +++ b/src/GEOM_SWIG/GEOM_TestOthers.py @@ -562,6 +562,18 @@ def TestOtherOperations (geompy, math): ind = ind + 1 pass + # TransferData + path = os.getenv("DATA_DIR") + fileName = path + "/Shapes/Step/black_and_white.step" + blackWhite = geompy.ImportSTEP(fileName) + blackWhiteCopy = geompy.MakeCopy(blackWhite[0]) + subBlackWhite = geompy.SubShapeAll(blackWhiteCopy, GEOM.SOLID) + geompy.TransferData(blackWhite[0], blackWhiteCopy) + geompy.addToStudy(blackWhite[0], "blackWhite") + geompy.addToStudy(blackWhiteCopy, "blackWhiteCopy") + geompy.addToStudyInFather( blackWhiteCopy, subBlackWhite[0], "" ) + geompy.addToStudyInFather( blackWhiteCopy, subBlackWhite[1], "" ) + # CheckAndImprove blocksComp = geompy.CheckAndImprove(part) diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py old mode 100644 new mode 100755 index c7aa61896..b5e1ca808 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -12934,6 +12934,46 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): RaiseIfFailed("AddTexture", self.InsertOp) return ID + ## Transfer not topological data from one GEOM object to another. + # + # @param theObjectFrom the source object of non-topological data + # @param theObjectTo the destination object of non-topological data + # @param theFindMethod method to search sub-shapes of theObjectFrom + # in shape theObjectTo. Possible values are: GEOM.FSM_GetInPlace, + # GEOM.FSM_GetInPlaceByHistory and GEOM.FSM_GetInPlace_Old. + # Other values of GEOM.find_shape_method are not supported. + # + # @return True in case of success; False otherwise. + # + # @ingroup l1_geomBuilder_auxiliary + # + # @ref swig_TransferData "Example" + @ManageTransactions("InsertOp") + def TransferData(self, theObjectFrom, theObjectTo, + theFindMethod=GEOM.FSM_GetInPlace): + """ + Transfer not topological data from one GEOM object to another. + + Parameters: + theObjectFrom the source object of non-topological data + theObjectTo the destination object of non-topological data + theFindMethod method to search sub-shapes of theObjectFrom + in shape theObjectTo. Possible values are: + GEOM.FSM_GetInPlace, GEOM.FSM_GetInPlaceByHistory + and GEOM.FSM_GetInPlace_Old. Other values of + GEOM.find_shape_method are not supported. + + Returns: + True in case of success; False otherwise. + + # Example: see GEOM_TestOthers.py + """ + # Example: see GEOM_TestAll.py + isOk = self.InsertOp.TransferData(theObjectFrom, + theObjectTo, theFindMethod) + RaiseIfFailed("TransferData", self.InsertOp) + return isOk + ## Creates a new folder object. It is a container for any GEOM objects. # @param Name name of the container # @param Father parent object. If None, diff --git a/src/OperationGUI/CMakeLists.txt b/src/OperationGUI/CMakeLists.txt index 0f8ae114e..b4c76b04f 100755 --- a/src/OperationGUI/CMakeLists.txt +++ b/src/OperationGUI/CMakeLists.txt @@ -76,6 +76,7 @@ SET(OperationGUI_HEADERS OperationGUI_GetSharedShapesDlg.h OperationGUI_ExtrudedFeatureDlg.h OperationGUI_ClippingDlg.h + OperationGUI_TransferDataDlg.h ) # header files / to be processed by moc @@ -89,6 +90,7 @@ SET(_moc_HEADERS OperationGUI_GetSharedShapesDlg.h OperationGUI_ExtrudedFeatureDlg.h OperationGUI_ClippingDlg.h + OperationGUI_TransferDataDlg.h ) # header files / uic wrappings @@ -110,6 +112,7 @@ SET(OperationGUI_SOURCES OperationGUI_ChamferDlg.cxx OperationGUI_ExtrudedFeatureDlg.cxx OperationGUI_ClippingDlg.cxx + OperationGUI_TransferDataDlg.cxx ${_moc_SOURCES} ${_uic_files} ) diff --git a/src/OperationGUI/OperationGUI.cxx b/src/OperationGUI/OperationGUI.cxx index a705e0ae2..e72c96d4e 100644 --- a/src/OperationGUI/OperationGUI.cxx +++ b/src/OperationGUI/OperationGUI.cxx @@ -39,6 +39,7 @@ #include "OperationGUI_GetShapesOnShapeDlg.h" #include "OperationGUI_GetSharedShapesDlg.h" #include "OperationGUI_ExtrudedFeatureDlg.h" // Methods EXTRUDED BOSS / CUT +#include "OperationGUI_TransferDataDlg.h" //======================================================================= // function : OperationGUI() @@ -81,6 +82,7 @@ bool OperationGUI::OnGUIEvent (int theCommandID, SUIT_Desktop* parent) case GEOMOp::OpExtrudedCut: (new OperationGUI_ExtrudedFeatureDlg (CUT, getGeometryGUI(), parent))->show(); break; case GEOMOp::OpFillet1d: (new OperationGUI_Fillet1d2dDlg (getGeometryGUI(), parent, true))->show(); break; case GEOMOp::OpFillet2d: (new OperationGUI_Fillet1d2dDlg (getGeometryGUI(), parent, false))->show(); break; + case GEOMOp::OpTransferData: (new OperationGUI_TransferDataDlg (getGeometryGUI(), parent))->show(); break; default: app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); } diff --git a/src/OperationGUI/OperationGUI_TransferDataDlg.cxx b/src/OperationGUI/OperationGUI_TransferDataDlg.cxx new file mode 100755 index 000000000..9c5d48f97 --- /dev/null +++ b/src/OperationGUI/OperationGUI_TransferDataDlg.cxx @@ -0,0 +1,331 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 +// + +#include "OperationGUI_TransferDataDlg.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +//============================================================================== +// class : OperationGUI_TransferDataDlg() +// purpose : Constructs a OperationGUI_TransferDataDlg which is a child of +// 'parent'. +//================================================================================= +OperationGUI_TransferDataDlg::OperationGUI_TransferDataDlg (GeometryGUI* theGeometryGUI, + QWidget* parent) + : GEOMBase_Skeleton(theGeometryGUI, parent, false), + myGroup(NULL) +{ + SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_TRANSFER_DATA"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_TRANSFER_DATA_TITLE")); + + /***************************************************************/ + mainFrame()->GroupConstructors->setTitle(tr("GEOM_TRANSFER_DATA")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton3->close(); + + mainFrame()->GroupBoxName->hide(); + + myGroup = new DlgRef_2Sel1List(centralWidget()); + myGroup->GroupBox1->setTitle(tr("GEOM_PARAMETERS")); + myGroup->TextLabel1->setText(tr("GEOM_TRANSFER_DATA_FROM")); + myGroup->TextLabel2->setText(tr("GEOM_TRANSFER_DATA_TO")); + myGroup->TextLabel3->setText(tr("GEOM_TRANSFER_DATA_METHOD")); + myGroup->PushButton1->setIcon(image1); + myGroup->PushButton2->setIcon(image1); + myGroup->LineEdit1->setReadOnly(true); + myGroup->LineEdit2->setReadOnly(true); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(myGroup); + /***************************************************************/ + + setHelpFileName("transfer_data_page.html"); + + Init(); +} + +//================================================================================= +// function : ~OperationGUI_TransferDataDlg +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +OperationGUI_TransferDataDlg::~OperationGUI_TransferDataDlg() +{ +} + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void OperationGUI_TransferDataDlg::Init() +{ + // type for detection + myGroup->ComboBox1->addItem(tr("GEOM_TD_METHOD_GETINPLACE")); + myGroup->ComboBox1->addItem(tr("GEOM_TD_METHOD_GETINPLACE_OLD")); + myGroup->ComboBox1->addItem(tr("GEOM_TD_METHOD_GETINPLACE_HISTORY")); + + myGroup->LineEdit1->clear(); + myGroup->LineEdit2->clear(); + myObject1.nullify(); + myObject2.nullify(); + + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + + connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + + connect(myGroup->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged())); + + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + myGroup->TextLabel3->show(); + myGroup->ComboBox1->show(); + myGroup->ComboBox1->setCurrentIndex(0); + + globalSelection(GEOM_ALLSHAPES); + + myGroup->PushButton1->click(); + SelectionIntoArgument(); + resize(100,100); +} + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void OperationGUI_TransferDataDlg::ClickOnOk() +{ + setIsApplyAndClose( true ); + if (ClickOnApply()) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool OperationGUI_TransferDataDlg::ClickOnApply() +{ + if (!onAccept(false)) + return false; + // activate first line edit + myGroup->PushButton1->click(); + return true; +} + +//================================================================================= +// function : SelectionIntoArgument() +// purpose : Called when selection is changed or on dialog initialization or activation +//================================================================================= +void OperationGUI_TransferDataDlg::SelectionIntoArgument() +{ + GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE); + + if (aSelectedObject) { + myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get())); + + if (myEditCurrentArgument == myGroup->LineEdit1) { + myObject1 = aSelectedObject; + + if (!myObject2) { + myGroup->PushButton2->click(); + } + } else if (myEditCurrentArgument == myGroup->LineEdit2) { + myObject2 = aSelectedObject; + + if (!myObject1) { + myGroup->PushButton1->click(); + } + } + } else { + myEditCurrentArgument->setText(""); + + if (myEditCurrentArgument == myGroup->LineEdit1) { + myObject1.nullify(); + } else if (myEditCurrentArgument == myGroup->LineEdit2) { + myObject2.nullify(); + } + } +} + +//================================================================================= +// function : SetEditCurrentArgument() +// purpose : +//================================================================================= +void OperationGUI_TransferDataDlg::SetEditCurrentArgument() +{ + QPushButton* send = (QPushButton*)sender(); + + if (send == myGroup->PushButton1) { + myEditCurrentArgument = myGroup->LineEdit1; + + myGroup->PushButton2->setDown(false); + myGroup->LineEdit2->setEnabled(false); + } + else if (send == myGroup->PushButton2) { + myEditCurrentArgument = myGroup->LineEdit2; + + myGroup->PushButton1->setDown(false); + myGroup->LineEdit1->setEnabled(false); + } + + // enable line edit + myEditCurrentArgument->setEnabled(true); + myEditCurrentArgument->setFocus(); + // after setFocus(), because it will be setDown(false) when loses focus + send->setDown(true); +} + +//================================================================================= +// function : LineEditReturnPressed() +// purpose : +//================================================================================= +void OperationGUI_TransferDataDlg::LineEditReturnPressed() +{ + QLineEdit* send = (QLineEdit*)sender(); + if (send == myGroup->LineEdit1 || send == myGroup->LineEdit2) + { + myEditCurrentArgument = send; + GEOMBase_Skeleton::LineEditReturnPressed(); + } +} + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +void OperationGUI_TransferDataDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + globalSelection(GEOM_ALLSHAPES); + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), + this, SLOT( SelectionIntoArgument() ) ); +} + +//================================================================================= +// function : enterEvent() +// purpose : when mouse enter onto the QWidget +//================================================================================= +void OperationGUI_TransferDataDlg::enterEvent (QEvent*) +{ + if (!mainFrame()->GroupConstructors->isEnabled()) + ActivateThisDialog(); +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr OperationGUI_TransferDataDlg::createOperation() +{ + return getGeomEngine()->GetIInsertOperations(getStudyId()); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool OperationGUI_TransferDataDlg::isValid(QString&) +{ + return myObject1 && myObject2; +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool OperationGUI_TransferDataDlg::execute (ObjectList& objects) +{ + const int aLimit = myGroup->ComboBox1->currentIndex(); + GEOM::find_shape_method aMethod; + + switch (aLimit) + { + case 0: + aMethod = GEOM::FSM_GetInPlace; + break; + case 1: + aMethod = GEOM::FSM_GetInPlace_Old; + break; + case 2: + default: + aMethod = GEOM::FSM_GetInPlaceByHistory; + break; + } + + GEOM::GEOM_IInsertOperations_var anOper = + GEOM::GEOM_IInsertOperations::_narrow(getOperation()); + GEOM::GEOM_IInsertOperations::ListOfTransferDatum_var aResult; + + bool isOK = anOper->TransferData + (myObject1.get(), myObject2.get(), aMethod, aResult); + + if (isOK) { + // Construct info message. + QString aMsg; + int aNbTypes = aResult->length(); + + if (aNbTypes == 0) { + aMsg = tr("GEOM_TRANSFER_DATA_NOT_COPIED"); + } else { + aMsg = tr("GEOM_TRANSFER_DATA_COPIED"); + aMsg += "\n"; + int i; + + for (i = 0; i < aNbTypes; i++ ) { + if (i > 0) { + aMsg += "\n"; + } + + aMsg += tr(aResult[i].myName). + arg(aResult[i].myNumber).arg(aResult[i].myMaxNumber); + } + } + + // Show info message. + SUIT_MessageBox::information + (SUIT_Session::session()->activeApplication()->desktop(), + tr("GEOM_TRANSFER_DATA_INFO"), aMsg, tr("BUT_OK")); + + objects.push_back(myObject2.copy()); + } + + return isOK; +} diff --git a/src/OperationGUI/OperationGUI_TransferDataDlg.h b/src/OperationGUI/OperationGUI_TransferDataDlg.h new file mode 100644 index 000000000..a4b6ef947 --- /dev/null +++ b/src/OperationGUI/OperationGUI_TransferDataDlg.h @@ -0,0 +1,68 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 +// + + +#ifndef OPERATIONGUI_TRANSFERDATADLG_H +#define OPERATIONGUI_TRANSFERDATADLG_H + + +#include + +class DlgRef_2Sel1List; + +//================================================================================= +// class : OperationGUI_TransferDataDlg +// purpose : +//================================================================================= +class OperationGUI_TransferDataDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + +public: + OperationGUI_TransferDataDlg + ( GeometryGUI* theGeometryGUI, QWidget* parent = 0 ); + ~OperationGUI_TransferDataDlg(); + +protected: + // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid( QString& ); + virtual bool execute( ObjectList& ); + +private: + void Init(); + void enterEvent( QEvent* ); + +private: + GEOM::GeomObjPtr myObject1; + GEOM::GeomObjPtr myObject2; + int myShapeType; + + DlgRef_2Sel1List* myGroup; + +private slots: + void ClickOnOk(); + bool ClickOnApply(); + void SetEditCurrentArgument(); + void SelectionIntoArgument(); + void LineEditReturnPressed(); + void ActivateThisDialog(); +}; + +#endif // OPERATIONGUI_GETSHAPESONSHAPEDLG_H