void Model_AttributeSelectionList::append(
const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
{
+ updateSubs();
+
int aNewTag = mySize->Get() + 1;
TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
boost::shared_ptr<ModelAPI_AttributeSelection>
Model_AttributeSelectionList::value(const int theIndex)
{
+ updateSubs();
return mySubs[theIndex];
}
void Model_AttributeSelectionList::clear()
{
- if (!mySubs.empty()) {
+ if (mySize->Get() != 0) {
mySize->Set(0);
mySubs.clear();
TDF_ChildIterator aSubIter(mySize->Label());
mySize = TDataStd_Integer::Set(theLabel, 0);
mySelectionType = TDataStd_Real::Set(theLabel, 0);
} else { // recollect mySubs
- int aNum = mySize->Get();
- TDF_ChildIterator aSubIter(theLabel);
- for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
- TDF_Label aChildLab = aSubIter.Value();
- boost::shared_ptr<Model_AttributeSelection> aNewAttr =
- boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
- if (owner())
- aNewAttr->setObject(owner());
- mySubs.push_back(aNewAttr);
- }
+ theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);
+ updateSubs();
}
}
(*aSubIter)->setObject(theObject);
}
}
+
+void Model_AttributeSelectionList::updateSubs()
+{
+ unsigned int aNum = mySize->Get();
+ if (aNum > mySubs.size()) { // add subs what are not yet created
+ TDF_ChildIterator aSubIter(mySize->Label());
+ for(int aExisting = mySubs.size(); aExisting > 0; aSubIter.Next()) aExisting--;
+ for(; aSubIter.More(); aSubIter.Next()) {
+ TDF_Label aChildLab = aSubIter.Value();
+ boost::shared_ptr<Model_AttributeSelection> aNewAttr =
+ boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
+ if (owner())
+ aNewAttr->setObject(owner());
+ mySubs.push_back(aNewAttr);
+ }
+ } else if (aNum < mySubs.size()) { // remove excess subs from the end
+ if (aNum == 0) {
+ mySubs.clear();
+ } else {
+ std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter;
+ for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--;
+ mySubs.erase(aSubIter, mySubs.end());
+ }
+ }
+}
#include "ModelAPI_Tools.h"
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultGroup.h>
namespace ModelAPI_Tools {
-boost::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
-{
- ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
- if (aBody)
- return aBody->shape();
- ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
+ boost::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
+ {
+
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aBody)
+ return aBody->shape();
+
+ ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
theResult);
- if (aConstruct)
- return aConstruct->shape();
- return boost::shared_ptr<GeomAPI_Shape>();
-}
+ if (aConstruct)
+ return aConstruct->shape();
+ ResultGroupPtr aGroup = boost::dynamic_pointer_cast<ModelAPI_ResultGroup>(theResult);
+ if (aGroup)
+ return aGroup->shape();
+ return boost::shared_ptr<GeomAPI_Shape>();
+ }
}
if (!aShape.IsNull()) {
theList.Append(aShape);
Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
- Handle(AIS_InteractiveObject) anObj =
- Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
- ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
- theOwners.push_back(anObject);
+ if (!aEO.IsNull()) {
+ Handle(AIS_InteractiveObject) anObj =
+ Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
+ ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
+ theOwners.push_back(anObject);
+ }
}
}
}