The problem was related to the Placement of parts feature - it adds additional transformation to all results and groups.
#include <GeomAPI_Shape.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Trsf.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
std::list<GeomShapePtr> aShapes;
std::list<ResultPtr> aResults;
std::list<DocumentPtr> aDocuments; /// documents of Parts selected and used in export
+ std::map<DocumentPtr, GeomTrsfPtr> aDocTrsf; /// translation of the part
AttributeSelectionListPtr aSelection = selectionList(SELECTION_LIST_ID());
bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
return;
} else {
aDocuments.push_back(aPartDoc);
+ aDocTrsf[aPartDoc] = aResPart->summaryTrsf();
}
}
}
try {
GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
- int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupResExplorer.current());
+ GeomShapePtr aGroupShape = aGroupResExplorer.current();
+ if (aDocTrsf.find(*aDoc) != aDocTrsf.end())
+ aGroupShape->move(aDocTrsf[*aDoc]);
+ int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupShape);
if (aReferenceID == 0) // selected value does not found in the exported shape
continue;
std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
#include <GeomAPI_Face.h>
#include <GeomAPI_Shell.h>
#include <GeomAPI_Solid.h>
+#include <GeomAPI_Trsf.h>
#include <BRep_Tool.hxx>
#include <BRepAlgoAPI_Section.hxx>
setImpl(new TopoDS_Shape(aResult));
}
+void GeomAPI_Shape::move(const std::shared_ptr<GeomAPI_Trsf> theTransformation)
+{
+ TopoDS_Shape aResult = MY_SHAPE->Moved(theTransformation->impl<gp_Trsf>());
+ setImpl(new TopoDS_Shape(aResult));
+}
+
bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const
{
BOPAlgo_CheckerSI aCSI; // checker of self-interferences
class GeomAPI_Face;
class GeomAPI_Shell;
class GeomAPI_Solid;
+class GeomAPI_Trsf;
/**\class GeomAPI_Shape
* \ingroup DataModel
GEOMAPI_EXPORT
void translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset);
+ /// Moves the shape with the given transformation matrix.
+ GEOMAPI_EXPORT
+ void move(const std::shared_ptr<GeomAPI_Trsf> theTransformation);
+
/// Returns type of shapes in the compound.
// If shapes are of different type then it will return SHAPE type
GEOMAPI_EXPORT ShapeType typeOfCompoundShapes() const;
GEOMAPI_EXPORT void setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane);
};
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Trsf> GeomTrsfPtr;
+
#endif
#include <TopoDS_Compound.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_CompoundBuilder::compound(
std::list<std::shared_ptr<GeomAPI_Shape> > theShapes)
return aRes;
}
+// Returns true if transformations are equal with the given precision
+static bool isEqual(const gp_Trsf& theT1, const gp_Trsf& theT2, const double thePrecision)
+{
+ for(int aRow = 1; aRow < 4; aRow++) {
+ for(int aCol = 1; aCol < 5; aCol++) {
+ double aDiff = theT1.Value(aRow, aCol) - theT2.Value(aRow, aCol);
+ if (aDiff < 0) aDiff = -aDiff;
+ if (aDiff > thePrecision)
+ return false;
+ }
+ }
+ return true;
+}
+
int GeomAlgoAPI_CompoundBuilder::id(
std::shared_ptr<GeomAPI_Shape> theContext, std::shared_ptr<GeomAPI_Shape> theSub)
{
TopTools_IndexedMapOfShape aSubShapesMap;
TopExp::MapShapes(aMainShape, aSubShapesMap);
anID = aSubShapesMap.FindIndex(aSubShape);
+ if (anID == 0) { // try to search shape with the same location if TopLoc_Location is different
+ TopExp_Explorer anExp(aMainShape, aSubShape.ShapeType());
+ for(; anExp.More(); anExp.Next()) {
+ if (anExp.Current().TShape() == aSubShape.TShape()) {
+ const TopLoc_Location aLoc1 = anExp.Current().Location();
+ if (isEqual(aLoc1.Transformation(), aSubShape.Location().Transformation(), 1.e-7)) {
+ anID = aSubShapesMap.FindIndex(anExp.Current());
+ break;
+ }
+ }
+ }
+ }
}
return anID;
static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
ModelAPI_EventCreator::get()->sendUpdated(theThis, EVENT_DISP); // flush is in preview-update
}
+
+std::shared_ptr<GeomAPI_Trsf> Model_ResultPart::summaryTrsf()
+{
+ GeomTrsfPtr aResult(new GeomAPI_Trsf);
+ aResult->setImpl<gp_Trsf>(new gp_Trsf(sumTrsf()));
+ return aResult;
+}
/// Applies the additional transformation of the part
MODEL_EXPORT virtual void setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
const std::shared_ptr<GeomAPI_Trsf>& theTransformation);
+ /// Returns the summary transformations of all references to the origin
+ MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Trsf> summaryTrsf();
/// Returns the parameters of color definition in the resources config manager
MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
virtual void setTrsf(std::shared_ptr<ModelAPI_Result> theThis,
const std::shared_ptr<GeomAPI_Trsf>& theTransformation) = 0;
+ /// Returns the summary transformations of all references to the origin
+ virtual std::shared_ptr<GeomAPI_Trsf> summaryTrsf() = 0;
+
/// Returns the shape by the name in the part
virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
const std::string& theName, const std::string& theType, int& theIndex) = 0;