Model_AttributeDocRef.h
Model_AttributeReference.h
Model_AttributeRefAttr.h
+ Model_AttributeRefList.h
Model_Events.h
)
Model_AttributeDocRef.cpp
Model_AttributeReference.cpp
Model_AttributeRefAttr.cpp
+ Model_AttributeRefList.cpp
Model_Events.cpp
)
--- /dev/null
+// File: ModelAPI_AttributeRefList.cxx
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeRefList.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+#include <ModelAPI_Feature.h>
+#include <Events_Loop.h>
+#include <TDF_ListIteratorOfLabelList.hxx>
+
+using namespace std;
+
+void Model_AttributeRefList::append(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ myRef->Append(aData->label());
+
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+}
+
+void Model_AttributeRefList::remove(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ myRef->Remove(aData->label());
+
+}
+
+int Model_AttributeRefList::size()
+{
+ return myRef->Extent();
+}
+
+list<boost::shared_ptr<ModelAPI_Feature> > Model_AttributeRefList::list()
+{
+ std::list< boost::shared_ptr<ModelAPI_Feature> > aResult;
+ boost::shared_ptr<Model_Document> aDoc =
+ boost::dynamic_pointer_cast<Model_Document>(feature()->document());
+ if (aDoc) {
+ const TDF_LabelList& aList = myRef->List();
+ for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
+ aResult.push_back(aDoc->feature(aLIter.Value()));
+ }
+ }
+ return aResult;
+}
+
+Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef)) {
+ myRef = TDataStd_ReferenceList::Set(theLabel);
+ }
+}
--- /dev/null
+// File: Model_AttributeRefList.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeRefList_HeaderFile
+#define Model_AttributeRefList_HeaderFile
+
+#include "Model.h"
+#include "ModelAPI_AttributeRefList.h"
+#include <TDataStd_ReferenceList.hxx>
+
+/**\class Model_AttributeRefList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to features (located in the same document).
+ */
+
+class Model_AttributeRefList : public ModelAPI_AttributeRefList
+{
+ Handle_TDataStd_ReferenceList myRef; ///< references to the features labels
+public:
+ /// Appends the feature to the end of a list
+ MODEL_EXPORT virtual void append(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+ /// Erases the first meet of the feature in the list
+ MODEL_EXPORT virtual void remove(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+ /// Returns number of features in the list
+ MODEL_EXPORT virtual int size();
+
+ /// Returns the list of features
+ MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Feature> > list();
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeDouble.h>
#include <Model_AttributeReference.h>
#include <Model_AttributeRefAttr.h>
+#include <Model_AttributeRefList.h>
#include <GeomData_Point.h>
#include <GeomData_Point2D.h>
#include <GeomData_Dir.h>
anAttr = new Model_AttributeReference(anAttrLab);
else if (theAttrType == ModelAPI_AttributeRefAttr::type())
anAttr = new Model_AttributeRefAttr(anAttrLab);
+ else if (theAttrType == ModelAPI_AttributeRefList::type())
+ anAttr = new Model_AttributeRefList(anAttrLab);
else if (theAttrType == GeomData_Point::type())
anAttr = new GeomData_Point(anAttrLab);
else if (theAttrType == GeomData_Dir::type())
return aRes;
}
+boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const string theID)
+{
+ map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ if (aFound == myAttrs.end()) {
+ // TODO: generate error on unknown attribute request and/or add mechanism for customization
+ return boost::shared_ptr<ModelAPI_AttributeRefList>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeRefList> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+}
+
boost::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string theID)
{
boost::shared_ptr<ModelAPI_Attribute> aResult;
friend class Model_Document;
friend class Model_AttributeReference;
friend class Model_AttributeRefAttr;
+ friend class Model_AttributeRefList;
public:
/// Returns the name of the feature visible by the user in the object browser
/// Returns the attribute that contains reference to an attribute of a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
refattr(const std::string theID);
+ /// Returns the attribute that contains list of references to features
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList>
+ reflist(const std::string theID);
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
TDataStd_Integer::Set(anObjLab, myFeatures[aGroup].size());
myFeatures[aGroup].push_back(theFeature);
// store feature in the history of features array
- Handle(TDataStd_ReferenceArray) aRefs;
- if (!groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
- aRefs = TDataStd_ReferenceArray::Set(groupLabel(FEATURES_GROUP), 0, 0);
- aRefs->SetValue(0, anObjLab);
- } else { // extend array by one more element
- Handle(TDataStd_HLabelArray1) aNewArray =
- new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper() + 1);
- for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
- aNewArray->SetValue(a, aRefs->Value(a));
+ if (theFeature->isInHistory()) {
+ Handle(TDataStd_ReferenceArray) aRefs;
+ if (!groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+ aRefs = TDataStd_ReferenceArray::Set(groupLabel(FEATURES_GROUP), 0, 0);
+ aRefs->SetValue(0, anObjLab);
+ } else { // extend array by one more element
+ Handle(TDataStd_HLabelArray1) aNewArray =
+ new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper() + 1);
+ for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
+ aNewArray->SetValue(a, aRefs->Value(a));
+ }
+ aNewArray->SetValue(aRefs->Upper() + 1, anObjLab);
+ aRefs->SetInternalArray(aNewArray);
}
- aNewArray->SetValue(aRefs->Upper() + 1, anObjLab);
- aRefs->SetInternalArray(aNewArray);
}
// event: feature is added
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeReference.h
ModelAPI_AttributeRefAttr.h
+ ModelAPI_AttributeRefList.h
)
SET(PROJECT_SOURCES
--- /dev/null
+// File: ModelAPI_AttributeRefList.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeRefList_HeaderFile
+#define ModelAPI_AttributeRefList_HeaderFile
+
+#include "ModelAPI_Attribute.h"
+#include <list>
+
+/**\class ModelAPI_AttributeRefList
+ * \ingroup DataModel
+ * \brief Attribute that contains list of references to features (located in the same document).
+ */
+
+class ModelAPI_AttributeRefList : public ModelAPI_Attribute
+{
+public:
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type() {return "RefList";}
+
+ /// Returns the type of this class of attributes, not static method
+ MODELAPI_EXPORT virtual std::string attributeType() {return type();}
+
+ /// Appends the feature to the end of a list
+ MODELAPI_EXPORT virtual void append(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+
+ /// Erases the first meet of the feature in the list
+ MODELAPI_EXPORT virtual void remove(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+
+ /// Returns number of features in the list
+ MODELAPI_EXPORT virtual int size() = 0;
+
+ /// Returns the list of features
+ MODELAPI_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Feature> > list() = 0;
+
+protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeRefList()
+ {}
+};
+
+#endif
class ModelAPI_AttributeDouble;
class ModelAPI_AttributeReference;
class ModelAPI_AttributeRefAttr;
+class ModelAPI_AttributeRefList;
class ModelAPI_Document;
class ModelAPI_Attribute;
virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string theID) = 0;
/// Returns the attribute that contains reference to an attribute of a feature
virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string theID) = 0;
+ /// Returns the attribute that contains list of references to features
+ virtual boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
/// Computes or recomputes the result
MODELAPI_EXPORT virtual void execute() = 0;
+ /// Returns true if this feature must be displayed in the history (top level of Part tree)
+ MODELAPI_EXPORT virtual bool isInHistory() {return true;}
+
/// Returns the data manager of this feature
MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Data> data() {return myData;}
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
#ifdef WIN32
#include <windows.h>
SKETCHPLUGIN_EXPORT virtual const void addSub(
const boost::shared_ptr<ModelAPI_Feature>& theFeature) = 0;
+ /// Returns true if this feature must be displayed in the history (top level of Part tree)
+ SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return false;}
+
protected:
/// Set the shape to the internal preview field
/// \param theShape a preview shape
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeRefList.h>
#include <GeomAPI_XYZ.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
data()->addAttribute(SKETCH_ATTR_DIRX, GeomDataAPI_Dir::type());
data()->addAttribute(SKETCH_ATTR_DIRY, GeomDataAPI_Dir::type());
data()->addAttribute(SKETCH_ATTR_NORM, GeomDataAPI_Dir::type());
+ data()->addAttribute(SKETCH_ATTR_FEATURES, ModelAPI_AttributeRefList::type());
}
void SketchPlugin_Sketch::execute()
const void SketchPlugin_Sketch::addSub(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
{
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
+ data()->reflist(SKETCH_ATTR_FEATURES)->append(theFeature);
}
void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
const std::string SKETCH_ATTR_DIRY("DirY");
/// Vector Z, normal to the sketch plane
const std::string SKETCH_ATTR_NORM("Norm");
+/// All features of this sketch (list of references)
+const std::string SKETCH_ATTR_FEATURES("Features");
/**\class SketchPlugin_Sketch
* \ingroup DataModel
SKETCHPLUGIN_EXPORT boost::shared_ptr<GeomAPI_Pnt> to3D(
const double theX, const double theY);
+ /// Returns true if this feature must be displayed in the history (top level of Part tree)
+ SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return true;}
+
/// Use plugin manager for features creation
SketchPlugin_Sketch();
protected: