Model_AttributeRefAttr.h
Model_AttributeRefList.h
Model_AttributeBoolean.h
+ Model_AttributeString.h
Model_Events.h
Model_Update.h
Model_Validator.h
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
+ Model_AttributeString.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
#include <TDataStd_Integer.hxx>
#include <TDF_Label.hxx>
-/**\class Model_AttributeDouble
+/**\class Model_AttributeBoolean
* \ingroup DataModel
* \brief Attribute that contains real value with double precision.
*/
--- /dev/null
+// File: Model_AttributeString.cpp
+// Created: 2 june 2014
+// Author: Vitaly Smetannikov
+
+#include <Model_AttributeString.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_Name.hxx>
+
+#include <string>
+
+void Model_AttributeString::setValue(const std::string& theValue)
+{
+ TCollection_ExtendedString aValue(theValue.c_str());
+ if (!myIsInitialized || myString->Get() != aValue) {
+ myString->Set(aValue);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+std::string Model_AttributeString::value()
+{
+ return TCollection_AsciiString(myString->Get()).ToCString();
+}
+
+Model_AttributeString::Model_AttributeString(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myString) == Standard_True;
+ if (!myIsInitialized) {
+ // create attribute: not initialized by value yet, just empty string
+ myString = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
+ }
+}
--- /dev/null
+// File: Model_AttributeString.h
+// Created: 2 june 2014
+// Author: Vitaly Smetannikov
+
+#ifndef Model_AttributeString_H_
+#define Model_AttributeString_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeString.h>
+
+#include <TDF_Label.hxx>
+#include <Handle_TDataStd_Name.hxx>
+
+#include <string>
+
+/**\class Model_AttributeString
+ * \ingroup DataModel
+ * \brief Attribute that contains std (null terminated) string.
+ */
+
+class Model_AttributeString : public ModelAPI_AttributeString
+{
+ Handle_TDataStd_Name myString; ///< double is Real attribute
+ public:
+ /// Defines the double value
+ MODEL_EXPORT virtual void setValue(const std::string& theValue);
+
+ /// Returns the double value
+ MODEL_EXPORT virtual std::string value();
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeString(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeRefAttr.h>
#include <Model_AttributeRefList.h>
#include <Model_AttributeBoolean.h>
+#include <Model_AttributeString.h>
+#include <Model_Events.h>
+
#include <GeomData_Point.h>
#include <GeomData_Point2D.h>
#include <GeomData_Dir.h>
-#include <TDataStd_Name.hxx>
-#include "Model_Events.h"
#include <Events_Loop.h>
#include <Events_Error.h>
-using namespace std;
+#include <TDataStd_Name.hxx>
Model_Data::Model_Data()
{
myLab = theLab;
}
-string Model_Data::name()
+std::string Model_Data::name()
{
Handle(TDataStd_Name) aName;
if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
- return string(TCollection_AsciiString(aName->Get()).ToCString());
+ return std::string(TCollection_AsciiString(aName->Get()).ToCString());
return ""; // not defined
}
-void Model_Data::setName(const string& theName)
+void Model_Data::setName(const std::string& theName)
{
bool isModified = false;
Handle(TDataStd_Name) aName;
}*/
}
-void Model_Data::addAttribute(const string& theID, const string theAttrType)
+void Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
{
TDF_Label anAttrLab = myLab.FindChild(myAttrs.size() + 1);
ModelAPI_Attribute* anAttr = 0;
- if (theAttrType == ModelAPI_AttributeDocRef::type())
+ if (theAttrType == ModelAPI_AttributeDocRef::type()) {
anAttr = new Model_AttributeDocRef(anAttrLab);
- else if (theAttrType == ModelAPI_AttributeDouble::type())
+ } else if (theAttrType == ModelAPI_AttributeDouble::type()) {
anAttr = new Model_AttributeDouble(anAttrLab);
- else if (theAttrType == ModelAPI_AttributeReference::type())
+ } else if (theAttrType == ModelAPI_AttributeReference::type()) {
anAttr = new Model_AttributeReference(anAttrLab);
- else if (theAttrType == ModelAPI_AttributeRefAttr::type())
+ } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
anAttr = new Model_AttributeRefAttr(anAttrLab);
- else if (theAttrType == ModelAPI_AttributeRefList::type())
+ } else if (theAttrType == ModelAPI_AttributeRefList::type()) {
anAttr = new Model_AttributeRefList(anAttrLab);
- else if (theAttrType == GeomData_Point::type())
+ } else if (theAttrType == GeomData_Point::type()) {
anAttr = new GeomData_Point(anAttrLab);
- else if (theAttrType == GeomData_Dir::type())
+ } else if (theAttrType == GeomData_Dir::type()) {
anAttr = new GeomData_Dir(anAttrLab);
- else if (theAttrType == GeomData_Point2D::type())
+ } else if (theAttrType == GeomData_Point2D::type()) {
anAttr = new GeomData_Point2D(anAttrLab);
- else if (theAttrType == Model_AttributeBoolean::type())
+ } else if (theAttrType == Model_AttributeBoolean::type()) {
anAttr = new Model_AttributeBoolean(anAttrLab);
-
+ } else if (theAttrType == Model_AttributeString::type()) {
+ anAttr = new Model_AttributeString(anAttrLab);
+ }
if (anAttr) {
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
anAttr->setObject(myObject);
}
}
-boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string& theID)
+boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const std::string& theID)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeDocRef>();
return aRes;
}
-boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const string& theID)
+boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string& theID)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeDouble>();
boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeBoolean>();
return aRes;
}
-boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const string& theID)
+boost::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string& theID)
+{
+ std::map<std::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_AttributeString>();
+ }
+ boost::shared_ptr<ModelAPI_AttributeString> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeString>(aFound->second);
+ if (!aRes) {
+ // TODO: generate error on invalid attribute type request
+ }
+ return aRes;
+
+}
+
+boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::string& theID)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeReference>();
return aRes;
}
-boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const string& theID)
+boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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_AttributeRefAttr>();
return aRes;
}
-boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const string& theID)
+boost::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const std::string& theID)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+ std::map<std::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>();
return myAttrs[theID];
}
-const string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr)
+const std::string& Model_Data::id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr)
{
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
for (; anAttr != myAttrs.end(); anAttr++) {
if (anAttr->second == theAttr)
return anAttr->first;
}
// not found
- static string anEmpty;
+ static std::string anEmpty;
return anEmpty;
}
return !myLab.IsNull() && myLab.HasAttribute();
}
-list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const string& theType)
+std::list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
{
- list<boost::shared_ptr<ModelAPI_Attribute> > aResult;
- map<string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = myAttrs.begin();
+ std::list<boost::shared_ptr<ModelAPI_Attribute> > aResult;
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = myAttrs.begin();
for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
aResult.push_back(anAttrsIter->second);
#ifndef Model_Data_H_
#define Model_Data_H_
-#include "Model.h"
+#include <Model.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+
#include <TDF_Label.hxx>
+#include <boost/smart_ptr/shared_ptr.hpp>
+
#include <map>
+#include <list>
+#include <string>
class ModelAPI_Attribute;
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
/// Returns the attribute that contains reference to a feature
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
- reference(const std::string& theID);
+ reference(const std::string& theID);
/// 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);
+ 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);
+ reflist(const std::string& theID);
/// Returns the attribute that contains boolean value
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean>
- boolean(const std::string& theID);
+ boolean(const std::string& theID);
+ /// Returns the attribute that contains real value with double precision
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeString>
+ string(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);
/// Returns all attributes ofthe feature of the given type
/// or all attributes if "theType" is empty
MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
- attributes(const std::string& theType);
+ attributes(const std::string& theType);
/// Identifier by the id (not fast, iteration by map)
/// \param theAttr attribute already created in this data
ModelAPI_AttributeRefAttr.h
ModelAPI_AttributeRefList.h
ModelAPI_AttributeBoolean.h
+ ModelAPI_AttributeString.h
ModelAPI_Events.h
ModelAPI_Validator.h
ModelAPI_FeatureValidator.h
#include "ModelAPI_Attribute.h"
#include "ModelAPI_AttributeDocRef.h"
#include "ModelAPI_AttributeDouble.h"
+ #include "ModelAPI_AttributeString.h"
#include "ModelAPI_AttributeReference.h"
#include "ModelAPI_AttributeRefAttr.h"
#include "ModelAPI_Validator.h"
%shared_ptr(ModelAPI_Attribute)
%shared_ptr(ModelAPI_AttributeDocRef)
%shared_ptr(ModelAPI_AttributeDouble)
+%shared_ptr(ModelAPI_AttributeString)
%shared_ptr(ModelAPI_AttributeReference)
%shared_ptr(ModelAPI_AttributeRefAttr)
%shared_ptr(ModelAPI_AttributeRefList)
%include "ModelAPI_Attribute.h"
%include "ModelAPI_AttributeDocRef.h"
%include "ModelAPI_AttributeDouble.h"
+%include "ModelAPI_AttributeString.h"
%include "ModelAPI_AttributeReference.h"
%include "ModelAPI_AttributeRefAttr.h"
%include "ModelAPI_Validator.h"
// Created: 2 june 2014
// Author: Vitaly Smetannikov
-#ifndef ModelAPI_AttributeBoolean_H_
-#define ModelAPI_AttributeBoolean_H_
+#ifndef MODELAPI_ATTRIBUTEBOOLEAN_H_
+#define MODELAPI_ATTRIBUTEBOOLEAN_H_
#include "ModelAPI_Attribute.h"
--- /dev/null
+// File: ModelAPI_AttributeString.h
+// Created: 2 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef MODELAPI_ATTRIBUTESTRING_H_
+#define MODELAPI_ATTRIBUTESTRING_H_
+
+#include "ModelAPI_Attribute.h"
+
+#include <string>
+
+/**\class ModelAPI_AttributeString
+ * \ingroup DataModel
+ * \brief API for the attribute that contains std (null terminated) string.
+ */
+
+class ModelAPI_AttributeString : public ModelAPI_Attribute
+{
+ public:
+ /// Defines the double value
+ MODELAPI_EXPORT virtual void setValue(const std::string& theValue) = 0;
+
+ /// Returns the double value
+ MODELAPI_EXPORT virtual std::string value() = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type()
+ {
+ return "String";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ MODELAPI_EXPORT virtual std::string attributeType()
+ {
+ return type();
+ }
+
+ /// To virtually destroy the fields of successors
+ MODELAPI_EXPORT virtual ~ModelAPI_AttributeString()
+ {
+ }
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeString()
+ {
+ }
+};
+
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeString> AttributeStringPtr;
+
+#endif
class ModelAPI_AttributeRefAttr;
class ModelAPI_AttributeRefList;
class ModelAPI_AttributeBoolean;
+class ModelAPI_AttributeString;
class ModelAPI_Document;
class ModelAPI_Attribute;
class GeomAPI_Shape;
virtual boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
/// Returns the attribute that contains boolean value
virtual boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
+ /// Returns the attribute that contains boolean value
+ virtual boost::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute