#define FACE 4
#define _MODIFY_TAG 1
#define _DELETED_TAG 2
+#define _SUBSOLIDS_TAG 3 /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
//=================================================================================================
FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
if(theBaseShape->isEqual(theAlgo.shape())) {
theResultBody->store(theAlgo.shape());
} else {
- theResultBody->storeModified(theBaseShape, theAlgo.shape());
+ theResultBody->storeModified(theBaseShape, theAlgo.shape(), _SUBSOLIDS_TAG);
GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
}
void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
- const std::shared_ptr<GeomAPI_Shape>& theNewShape)
+ const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
if (aShapeNew.IsNull())
return; // null shape inside
aBuilder.Modify(aShapeOld, aShapeNew);
+ if (theDecomposeSolidsTag && aShapeNew.ShapeType() == TopAbs_COMPOUND) { // make sub elements as subs
+
+ // register name if it is possible
+ TCollection_AsciiString aName;
+ if(!aBuilder.NamedShape()->IsEmpty()) {
+ Handle(TDataStd_Name) anAttr;
+ if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+ aName = TCollection_AsciiString(anAttr->Get()).ToCString();
+ }
+ }
+
+ TopoDS_Iterator aSubIter(aShapeNew);
+ for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) {
+ TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++));
+ aSubBuilder.Generated(aSubIter.Value());
+ if(!aName.IsEmpty()) {
+ std::string aSolidName =
+ (aName + "_Solid_" + TCollection_AsciiString(aTag - theDecomposeSolidsTag)).ToCString();
+ std::shared_ptr<Model_Document> aDoc =
+ std::dynamic_pointer_cast<Model_Document>(document());
+ aDoc->addNamingName(aSubBuilder.NamedShape()->Label(), aSolidName);
+ TDataStd_Name::Set(aSubBuilder.NamedShape()->Label(), aSolidName.c_str());
+ }
+ }
+ }
}
}
const std::shared_ptr<GeomAPI_Shape>& theToShape);
/// Stores the modified shape (called by the execution method).
+ /// \param theOldShape shape that produces result
+ /// \param theNewShape resulting shape
+ /// \param theDecomposeSolidsTag tag for starting of solids sub-elements placement in case
+ /// theNewShape is compound of solids, if zero it is not used
MODEL_EXPORT virtual void storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
- const std::shared_ptr<GeomAPI_Shape>& theNewShape);
+ const std::shared_ptr<GeomAPI_Shape>& theNewShape,
+ const int theDecomposeSolidsTag = 0);
/// Returns the shape-result produced by this feature
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Feature.h>
std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
{
}
}
if (aDocRef->value().get()) {
+ SessionPtr aMgr = ModelAPI_Session::get();
+ bool isNewTransaction = !aMgr->isOperation();
+ // activation may cause changes in current features in document, so it must be in transaction
+ if (isNewTransaction) {
+ aMgr->startOperation("Activation");
+ }
ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
+ if (isNewTransaction) {
+ aMgr->finishOperation();
+ }
}
}
std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
return aDocRef->value().get();
}
+
+bool Model_ResultPart::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
+ const bool theFlag)
+{
+ if (ModelAPI_ResultPart::setDisabled(theThis, theFlag)) {
+ DocumentPtr aDoc = Model_ResultPart::partDoc();
+ if (aDoc.get()) {
+ if (theFlag) { // disable, so make all features disabled too
+ aDoc->setCurrentFeature(FeaturePtr(), false);
+ } else { // enabled, so make the current feature the last inside of this document
+ FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aDoc->object(
+ ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1));
+ aDoc->setCurrentFeature(aLastFeature, false);
+ }
+ }
+ return true;
+ }
+ return false;
+}
/// Sets this document as current and if it is not loaded yet, loads it
MODEL_EXPORT virtual void activate();
+ /// disable all feature of the part on disable of the part result
+ MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
+ const bool theFlag);
+
protected:
/// makes a result on a temporary feature (an action)
Model_ResultPart();
#include <Config_ModuleReader.h>
#include <Config_ValidatorReader.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
#include <TDF_CopyTool.hxx>
#include <TDF_DataSet.hxx>
return myCurrentDoc;
}
+/// makes the last feature in the document as the current
+static void makeCurrentLast(std::shared_ptr<ModelAPI_Document> theDoc) {
+ if (theDoc.get()) {
+ FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theDoc->object(
+ ModelAPI_Feature::group(), theDoc->size(ModelAPI_Feature::group()) - 1));
+ theDoc->setCurrentFeature(aLastFeature, false);
+ }
+}
+
void Model_Session::setActiveDocument(
std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
{
if (myCurrentDoc != theDoc) {
+ std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
myCurrentDoc = theDoc;
if (theDoc.get() && theSendSignal) {
// syncronize the document: it may be just opened or opened but removed before
new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)));
Events_Loop::loop()->send(aMsg);
}
+ // make the current state correct and synchronised in the module and sub-documents
+ if (isOperation()) { // do it only in transaction, not on opening of document
+ if (myCurrentDoc == moduleDocument()) {
+ // make the current feature the latest in root, in previous root current become also last
+ makeCurrentLast(aPrevious);
+ makeCurrentLast(myCurrentDoc);
+ } else {
+ // make the current feature the latest in sub, root current feature becomes this sub
+ makeCurrentLast(myCurrentDoc);
+ DocumentPtr aRoot = moduleDocument();
+ ResultPtr aPartRes = ModelAPI_Tools::findPartResult(aRoot, myCurrentDoc);
+ if (aPartRes.get()) {
+ FeaturePtr aPartFeat = aRoot->feature(aPartRes);
+ if (aPartFeat.get()) {
+ aRoot->setCurrentFeature(aPartFeat, false);
+ }
+ }
+ }
+ }
}
}
std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleted =
std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
if (aDeleted &&
- aDeleted->groups().find(ModelAPI_ResultPart::group()) != aDeleted->groups().end())
+ aDeleted->groups().find(ModelAPI_ResultPart::group()) != aDeleted->groups().end() &&
+ !ModelAPI_Tools::findPartResult(moduleDocument(), activeDocument()).get()) // another part may be disabled
{
setActiveDocument(moduleDocument());
}
/// Stores the modified shape (called by the execution method).
virtual void storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
- const std::shared_ptr<GeomAPI_Shape>& theNewShape) = 0;
+ const std::shared_ptr<GeomAPI_Shape>& theNewShape,
+ const int theDecomposeSolidsTag = 0) = 0;
/// Records the subshape newShape which was generated during a topological construction.
/// As an example, consider the case of a face generated in construction of a box.
#include <ModelAPI_Object.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_ResultParameter.h>
-
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_AttributeDocRef.h>
#include <list>
#include <map>
}
}
+ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)
+{
+ for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
+ theMain->object(ModelAPI_ResultPart::group(), a));
+ if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
+ return aPart;
+ }
+ }
+ return ResultPtr();
+}
+
} // namespace ModelAPI_Tools
#include "ModelAPI.h"
#include <ModelAPI_Result.h>
#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
#include <GeomAPI_Shape.h>
#include <vector>
*/
MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
+/*!
+ * Searches for Part result that contains the reference to the given document.
+ * \param theMain document that contains the searched feature
+ * \param theSub document that is searched, the resulting feature references to it
+ * \returns numm if not found
+ */
+MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
+
}
#endif
void PartSet_MenuMgr::onActivatePartSet(bool)
{
SessionPtr aMgr = ModelAPI_Session::get();
+ bool isNewTransaction = !aMgr->isOperation();
+ // activation may cause changes in current features in document, so it must be in transaction
+ if (isNewTransaction) {
+ aMgr->startOperation("Activation");
+ }
aMgr->setActiveDocument(aMgr->moduleDocument());
+ if (isNewTransaction) {
+ aMgr->finishOperation();
+ }
}
void PartSet_MenuMgr::onEdit(bool)
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Tools.h>
void PartSetPlugin_Remove::execute()
{
std::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
std::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
- std::shared_ptr<PartSetPlugin_Part> a;
- for (int a = aRoot->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
- aRoot->object(ModelAPI_ResultPart::group(), a));
- if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == document()) {
- FeaturePtr aFeature = aRoot->feature(aPart);
- if (aFeature) {
- // do remove
- aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
- std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
- aRoot->refsToFeature(aFeature, aRefFeatures);
- if (aRefFeatures.empty())
- aRoot->removeFeature(aFeature);
- }
+ DocumentPtr aThisDoc = document();
+ ResultPtr aPart = ModelAPI_Tools::findPartResult(aRoot, aThisDoc);
+ if (aPart.get()) {
+ FeaturePtr aFeature = aRoot->feature(aPart);
+ if (aFeature) {
+ // do remove
+ aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
+ std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
+ aRoot->refsToFeature(aFeature, aRefFeatures);
+ if (aRefFeatures.empty())
+ aRoot->removeFeature(aFeature);
}
}
}