// for each selected face generate a result
int anIndex = 0, aResultIndex = 0;
+
for(; anIndex < aFaceRefs->size(); anIndex++) {
std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = aFaceRefs->value(anIndex);
ResultPtr aContextRes = aFaceRef->context();
}
}
+#ifdef DEBUG_COMPSOLID
+ ResultCompSolidPtr aCompSolidResult = document()->createCompSolid(data(), aResultIndex);
+ setResult(aCompSolidResult, aResultIndex);
+ aResultIndex++;
+#endif
for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
- //ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
#ifdef DEBUG_COMPSOLID
- ResultCompSolidPtr aResultBody = document()->createCompSolid(data(), aResultIndex);
+ ResultBodyPtr aResultBody = aCompSolidResult->addResult(aResultIndex);
#else
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
#endif
break;
}
//LoadNamingDS
-#ifdef DEBUG_COMPSOLID
-#else
+//#ifdef DEBUG_COMPSOLID
+//#else
LoadNamingDS(aFeature, aResultBody, aBaseShape, aContext);
-#endif
+//#endif
setResult(aResultBody, aResultIndex);
aResultIndex++;
#include <Model_ResultCompSolid.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Object.h>
+
+#include <Model_Document.h>
+
Model_ResultCompSolid::Model_ResultCompSolid()
{
}
{
}
-std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::addResult(std::string theID)
+void Model_ResultCompSolid::initAttributes()
+{
+ data()->addAttribute(Model_ResultCompSolid::BODIES_ID(), ModelAPI_AttributeRefList::typeId());
+}
+
+std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::addResult(const int theIndex)
{
- std::shared_ptr<ModelAPI_ResultBody> aResult;
- return aResult;
+ std::shared_ptr<ModelAPI_ResultBody> aBody = document()->createBody(data(), theIndex);
+ if (aBody.get()) {
+ data()->reflist(Model_ResultCompSolid::BODIES_ID())->append(aBody);
+ }
+ return aBody;
}
int Model_ResultCompSolid::numberOfSubs(bool forTree) const
std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int theIndex,
bool forTree) const
{
- std::shared_ptr<ModelAPI_ResultBody> aBody;
+ if (forTree) {
+ std::shared_ptr<ModelAPI_ResultBody> aBody;
+ return aBody;
+ }
- return aBody;
+ ObjectPtr anObj = data()->reflist(Model_ResultCompSolid::BODIES_ID())->object(theIndex);
+ return std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObj);
}
-int Model_ResultCompSolid::subResultId(const int theIndex) const
+/*int Model_ResultCompSolid::subResultId(const int theIndex) const
{
- return 0;
-}
+ return subResult(theIndex)->data()->featureId();
+}*/
bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
{
- return true;
+ // check is this feature of result
+ ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
+ /*if (!aFeature) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aRes)
+ aFeature = document()->feature(aRes);
+ }*/
+ if (aResult) {
+ return data()->reflist(Model_ResultCompSolid::BODIES_ID())->isInList(aResult);
+ }
+ return false;
}
void Model_ResultCompSolid::removeResult(std::shared_ptr<ModelAPI_ResultBody> theResult)
{
+ if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
+ return;
+
+ std::list<ObjectPtr> aSubs = data()->reflist(Model_ResultCompSolid::BODIES_ID())->list();
+
+ std::list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
+ bool isRemoved = false;
+ bool aHasEmtpyResult = false;
+ for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
+ std::shared_ptr<ModelAPI_ResultBody> aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aSubIt);
+ if (aResult.get() != NULL && aResult == theResult) {
+ data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(aResult);
+ isRemoved = true;
+ }
+ else if (aResult.get() == NULL)
+ aHasEmtpyResult = true;
+ }
+ // if the object is not found in the sketch sub-elements, that means that the object is removed already.
+ // Find the first empty element and remove it
+ if (!isRemoved && aHasEmtpyResult)
+ data()->reflist(Model_ResultCompSolid::BODIES_ID())->remove(ObjectPtr());
}
class Model_ResultCompSolid : public ModelAPI_ResultCompSolid
{
public:
+ /// All features of this sketch (list of references)
+ inline static const std::string& BODIES_ID()
+ {
+ static const std::string MY_BODIES_ID("Bodies");
+ return MY_BODIES_ID;
+ }
+
/// Removes the stored builders
MODEL_EXPORT virtual ~Model_ResultCompSolid();
+ /// Request for initialization of data model of the object: adding all attributes
+ MODEL_EXPORT virtual void initAttributes();
+
/// Adds result to the sketch and to its document
- virtual std::shared_ptr<ModelAPI_ResultBody> addResult(std::string theID);
+ /// \param theIndex an index of the created body result in the compsolid
+ /// The real index in the document of the result is an incremented given index
+ /// The reason is that the first index is used for the comp solid result on the data
+ virtual std::shared_ptr<ModelAPI_ResultBody> addResult(const int theIndex);
/// Returns the number of sub-elements
virtual int numberOfSubs(bool forTree = false) const;
bool forTree = false) const;
/// Returns the sub-feature unique identifier in this composite feature by zero-base index
- virtual int subResultId(const int theIndex) const;
+ //virtual int subResultId(const int theIndex) const;
/// Returns true if feature or reuslt belong to this composite feature as subs
virtual bool isSub(ObjectPtr theObject) const;
return group();
}
-void ModelAPI_ResultCompSolid::initAttributes()
-{
-}
-
bool ModelAPI_ResultCompSolid::isDisabled() const
{
return false;
/// Returns the group identifier of this result
inline static std::string group()
{
- static std::string MY_GROUP = "CompSolid";
+ static std::string MY_GROUP = "Bodies";
return MY_GROUP;
}
- /// Request for initialization of data model of the object: adding all attributes
- MODELAPI_EXPORT virtual void initAttributes();
-
/// Returns the feature is disabled or not.
MODELAPI_EXPORT virtual bool isDisabled() const;
/// Adds result to the sketch and to its document
- virtual std::shared_ptr<ModelAPI_ResultBody> addResult(std::string theID) = 0;
+ /// \param theIndex an index of the created body result in the compsolid
+ virtual std::shared_ptr<ModelAPI_ResultBody> addResult(const int theIndex) = 0;
/// Returns the number of sub-elements
virtual int numberOfSubs(bool forTree = false) const = 0;
bool forTree = false) const = 0;
/// Returns the sub-feature unique identifier in this composite feature by zero-base index
- virtual int subResultId(const int theIndex) const = 0;
+ //virtual int subResultId(const int theIndex) const = 0;
/// Returns true if feature or reuslt belong to this composite feature as subs
virtual bool isSub(ObjectPtr theObject) const = 0;