// Setting result.
if (isPart) {
ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
-
- ResultPartPtr aCurrentResult;
- const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aResults.begin();
- for(int a = 0; aResIter != aResults.end(); aResIter++, a++) {
- if (a == aResultIndex) {
- aCurrentResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aResIter);
- break;
- }
- }
- ResultPartPtr aResultPart = document()->copyPart(aCurrentResult, anOrigin, aResultIndex);
+ ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
aResultPart->setTrsf(*aContext, aMovementAlgo.transformation());
setResult(aResultPart);
} else {
bool isReverse = boolean(REVERSE_ID())->value();
bool isCentering = boolean(CENTERING_ID())->value();
- bool isPart = aContextRes->groupName() == ModelAPI_ResultPart::group();
-
// Getting transformation.
GeomAlgoAPI_Placement aPlacementAlgo(
aStartShape, anEndShape, aStartFace, anEndFace, isReverse, isCentering, true);
for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
anObjectsIt++, aContext++) {
- if (isPart) { // for part results just set transformation
- ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aContextRes);
- ResultPartPtr aResultPart = document()->copyPart(firstResult(), anOrigin);
+ if ((*aContext)->groupName() == ModelAPI_ResultPart::group()) { // for part results just set transformation
+ ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
+ ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
aResultPart->setTrsf(aContextRes, aTrsf);
- setResult(aResultPart);
+ setResult(aResultPart, aResultIndex);
} else {
std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
GeomAlgoAPI_Transform aTransformAlgo(aBaseShape, aTrsf);
// Setting result.
if (isPart) {
ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
-
- ResultPartPtr aCurrentResult;
- const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aResults.begin();
- for(int a = 0; aResIter != aResults.end(); aResIter++, a++) {
- if (a == aResultIndex) {
- aCurrentResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aResIter);
- break;
- }
- }
- ResultPartPtr aResultPart = document()->copyPart(aCurrentResult, anOrigin, aResultIndex);
+ ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
aResultPart->setTrsf(*aContext, aRotationAlgo.transformation());
setResult(aResultPart);
} else {
label="Select a solid objects"
icon=":icons/cut_shape.png"
tooltip="Select a solid objects"
- type_choice="Solids">
+ type_choice="Solids"
+ concealment="true" >
</multi_selector>
<shape_selector id="placement_start_face"
label="Select an object"
label="Select an object"
icon=":icons/placement_to.png"
tooltip="Select an end face"
- shape_types="face"
- concealment="true" >
+ shape_types="face" >
<validator id="PartSet_DifferentObjects"/>
</shape_selector>
<boolvalue id="placement_reverse_direction"
TopLoc_Location aDelta(aTrsf);
aResult = aSourceShape.Moved(aDelta);
// store the accumulated information about the result and this delta
- myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
+ //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
+ myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
myDone = true; // is OK for sure
} else {
BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
TopoDS_Shape aResult = aSourceShape.Moved(aDelta);
myShape->setImpl(new TopoDS_Shape(aResult));
// store the accumulated information about the result and this delta
- myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
+ //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
+ myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
myDone = true; // it is allways true for simple transformation generation
} else { // internal rebuild of the shape
// Transform the shape with copying it
if (theSimpleTransform) {
TopLoc_Location aDelta(aTrsf);
aResult = aSourceShape.Moved(aDelta);
- myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
+ //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
+ myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
myDone = true; // is OK for sure
} else {
BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
}
std::shared_ptr<ModelAPI_ResultPart> Model_Document::copyPart(
- const std::shared_ptr<ModelAPI_Result>& theOldPart,
- const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
- const int theIndex)
+ const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
- return myObjs->copyPart(theOldPart, theOrigin, theIndex);
+ return myObjs->copyPart(theOrigin, theFeatureData, theIndex);
}
std::shared_ptr<ModelAPI_ResultGroup> Model_Document::createGroup(
/// Creates a part results
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
- //! Copies a part result, keeping the same data
+ //! Copies a part result, keeping the reference to origin
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
- const std::shared_ptr<ModelAPI_Result>& theOldPart,
- const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
- const int theIndex = 0);
+ const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
/// Creates a group results
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
}
std::shared_ptr<ModelAPI_ResultPart> Model_Objects::copyPart(
- const std::shared_ptr<ModelAPI_Result>& theOldPart,
- const std::shared_ptr<ModelAPI_ResultPart>& theOrigin, const int theIndex)
+ const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
- std::shared_ptr<ModelAPI_ResultPart> aResult;
- if (theOldPart.get()) {
- aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theOldPart);
- }
- if (!aResult) {
- aResult = std::shared_ptr<ModelAPI_ResultPart>(new Model_ResultPart);
- aResult->setDoc(myDoc);
- aResult->setData(theOrigin->data());
- }
+ std::shared_ptr<ModelAPI_ResultPart> aResult = createPart(theFeatureData, theIndex);
+ aResult->data()->reference(Model_ResultPart::BASE_REF_ID())->setValue(theOrigin);
return aResult;
}
/// Creates a part results
std::shared_ptr<ModelAPI_ResultPart> createPart(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
- /// Copies a part results, keeping the same data
+ /// Copies a part results, keeping the reference to origin
std::shared_ptr<ModelAPI_ResultPart> copyPart(
- const std::shared_ptr<ModelAPI_Result>& theOldPart,
- const std::shared_ptr<ModelAPI_ResultPart>& theOrigin, const int theIndex = 0);
+ const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
/// Creates a group results
std::shared_ptr<ModelAPI_ResultGroup> createGroup(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeReference.h>
#include <Model_Document.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
#include <BRep_Builder.hxx>
#include <TopExp_Explorer.hxx>
+#define baseRef() std::dynamic_pointer_cast<Model_ResultPart>(data()->reference(BASE_REF_ID())->value())
+
void Model_ResultPart::initAttributes()
{
// append the color attribute. It is empty, the attribute will be filled by a request
data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::typeId());
data()->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
+ data()->addAttribute(BASE_REF_ID(), ModelAPI_AttributeReference::typeId());
}
std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
{
+ if (myTrsf.get()) {
+ return baseRef()->partDoc();
+ }
return data()->document("PartDocument")->value();
}
-std::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
-{
- return std::shared_ptr<ModelAPI_Feature>(); // return empty pointer
-}
-
Model_ResultPart::Model_ResultPart()
{
myIsDisabled = true; // by default it is not initialized and false to be after created
void Model_ResultPart::activate()
{
+ if (myTrsf.get()) {
+ baseRef()->activate();
+ return;
+ }
+
std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
if (!aDocRef->value().get()) { // create (or open) a document if it is not yet created
bool Model_ResultPart::isActivated()
{
+ if (myTrsf.get()) {
+ return baseRef()->isActivated();
+ }
+
std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
return aDocRef->value().get() != NULL;
}
{
std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
if (myTrsf.get()) { // get shape of the base result and apply the transformation
- ResultPtr anOrigResult =
- std::dynamic_pointer_cast<ModelAPI_Result>(data()->attribute(COLOR_ID())->owner());
+ ResultPtr anOrigResult = baseRef();
std::shared_ptr<GeomAPI_Shape> anOrigShape = anOrigResult->shape();
if (anOrigShape.get()) {
TopoDS_Shape aShape = anOrigShape->impl<TopoDS_Shape>();
theIndex = 0; // not initialized
if (myTrsf.get()) { // if this is moved copy of part => return the name of original shape
- ResultPartPtr anOrigResult =
- std::dynamic_pointer_cast<ModelAPI_ResultPart>(data()->attribute(COLOR_ID())->owner());
+ ResultPartPtr anOrigResult = baseRef();
// searching in the origin the shape equal to the given but with myTrsf
TopoDS_Shape aSelection = theShape->impl<TopoDS_Shape>();
gp_Trsf aSelTrsf = aSelection.Location().Transformation();
TopoDS_Shape myShape; ///< shape of this part created from bodies (updated only of Part deactivation)
std::shared_ptr<gp_Trsf> myTrsf; ///< if it is just copy of original shape, keep just transformation
public:
+
+ /// the reference to the base result document, may be null if this is the root, others make sequence of references
+ inline static const std::string& BASE_REF_ID()
+ {
+ static const std::string MY_BASE_REF("BaseReference");
+ return MY_BASE_REF;
+ }
/// Request for initialization of data model of the result: adding all attributes
virtual void initAttributes();
/// Returns the part-document of this result
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> partDoc();
- /// Part has no stored feature: this method returns NULL
- MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> owner();
/// Sets this document as current and if it is not loaded yet, loads it
MODEL_EXPORT virtual void activate();
%{
#include "ModelAPI.h"
+ #include "ModelAPI_Entity.h"
#include "ModelAPI_Document.h"
#include "ModelAPI_Session.h"
#include "ModelAPI_Object.h"
// shared pointers
// For ModelAPI_ResultConstruction.shape()
+%shared_ptr(ModelAPI_Entity)
%shared_ptr(ModelAPI_Document)
%shared_ptr(ModelAPI_Session)
%shared_ptr(ModelAPI_Plugin)
%shared_ptr(ModelAPI_ResultParameter)
// all supported interfaces
+%include "ModelAPI_Entity.h"
%include "ModelAPI_Document.h"
%include "ModelAPI_Session.h"
%include "ModelAPI_Plugin.h"
//! Creates a part results
virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
- //! Copies a part result, keeping the same data
+ //! Copies a part result, keeping the reference to the origin
virtual std::shared_ptr<ModelAPI_ResultPart> copyPart(
- const std::shared_ptr<ModelAPI_Result>& theOldPart,
- const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
- const int theIndex = 0) = 0;
+ const std::shared_ptr<ModelAPI_ResultPart>& theOrigin,
+ const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
//! Creates a group results
virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
// get feature
FeaturePtr aFeature = anOperationMgr->currentOperation()->feature();
- if (!aFeature.get())
+ if (!aFeature.get() || !aFeature->data()->isValid())
return;
// set error indication