Commit 4aa7430c authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Migrated comment functionality into BaseObject.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16144 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e01810ef
......@@ -1102,26 +1102,7 @@ QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) {
if (visibleOnly && !o_it->visible()) continue;
OpenMesh::BaseKernel *mesh = 0;
{
TriMeshObject * const triMeshObj = dynamic_cast<TriMeshObject*>(*o_it);
if (triMeshObj) {
mesh = triMeshObj->mesh();
}
PolyMeshObject * const polyMeshObj = dynamic_cast<PolyMeshObject*>(*o_it);
if (polyMeshObj) {
mesh = polyMeshObj->mesh();
}
}
if (mesh) {
OpenMesh::MPropHandleT<std::string> mp_comment;
if (mesh->get_property_handle(mp_comment, "COMMENT")) {
result.append(QString("Object \"%1\" Comment Begin\n%2\nObject \"%1\" Comment End\n")
.arg((*o_it)->name())
.arg(QString::fromStdString(mesh->property(mp_comment))));
}
}
result.append(o_it->getAllCommentsFlat());
}
return result;
}
......
......@@ -186,11 +186,11 @@ BaseObject::~BaseObject() {
// Object Identification
// ===============================================================================
int BaseObject::id() {
int BaseObject::id() const {
return id_;
}
int BaseObject::persistentId() {
int BaseObject::persistentId() const {
return persistentId_;
}
......@@ -217,7 +217,7 @@ void BaseObject::cleanup() {
// Data Type Handling
// ===============================================================================
bool BaseObject::dataType(DataType _type) {
bool BaseObject::dataType(DataType _type) const {
if ( _type == DATA_ALL ) {
return true;
}
......@@ -225,7 +225,7 @@ bool BaseObject::dataType(DataType _type) {
return ( objectType_ & _type);
}
DataType BaseObject::dataType() {
DataType BaseObject::dataType() const {
return BaseObject::objectType_;
}
......@@ -469,6 +469,11 @@ BaseObject* BaseObject::parent()
return parentItem_;
}
const BaseObject* BaseObject::parent() const
{
return parentItem_;
}
/// Set the parent pointer
void BaseObject::setParent(BaseObject* _parent) {
// remove this child from the old parents list
......@@ -594,7 +599,7 @@ void BaseObject::deleteSubtree() {
// ===============================================================================
// Grouping
// ===============================================================================
int BaseObject::group() {
int BaseObject::group() const {
// Skip root node
if ( parent() == 0 )
return -1;
......@@ -612,14 +617,14 @@ int BaseObject::group() {
}
bool BaseObject::isGroup() {
bool BaseObject::isGroup() const {
// return ( (childItems_.size() > 0) || dataType(DATA_GROUP) ) ;
return ( dataType(DATA_GROUP) ) ;
};
bool BaseObject::isInGroup( int _id ) {
BaseObject* current = this;
bool BaseObject::isInGroup( int _id ) const {
const BaseObject* current = this;
// Go up and check for the group id
do {
......@@ -635,8 +640,8 @@ bool BaseObject::isInGroup( int _id ) {
return false;
}
bool BaseObject::isInGroup( QString _name ) {
BaseObject* current = this;
bool BaseObject::isInGroup( QString _name ) const {
const BaseObject* current = this;
// Go up and check for the group name
do {
......@@ -699,7 +704,7 @@ QStringList BaseObject::getGroupNames() {
// Name and path Handling
// ===============================================================================
QString BaseObject::filename()
QString BaseObject::filename() const
{
return filename_;
}
......@@ -723,11 +728,11 @@ void BaseObject::setName(QString _name ) {
emit objectPropertiesChanged(id());
}
QString BaseObject::name() {
QString BaseObject::name() const {
return name_;
}
QString BaseObject::path(){
QString BaseObject::path() const {
return path_;
}
......
......@@ -109,13 +109,13 @@ class DLLEXPORTONLY BaseObject : public QObject {
/** return the unique id of the object. These ids will be generated every time an object is created.
* It will stay valid during the runtime of the application.
*/
int id();
int id() const;
/** return the persistent id of an object ( This id can be managed by a database ). It should
* be persistent across program starts. It will be -1 if the object has not been registered by
* a database. This id will only be set if a database plugin manages it.
*/
int persistentId();
int persistentId() const;
/** set the persistent id of the object
*/
......@@ -145,11 +145,11 @@ class DLLEXPORTONLY BaseObject : public QObject {
/** Check the if the object is of the given type
* @param _type checks, if the object is of the given type
*/
bool dataType(DataType _type);
bool dataType(DataType _type) const;
/** return the dataType of the object
*/
DataType dataType();
DataType dataType() const;
/** set the object type
* @param _type the type of the object (if it has a type defined, it will output a warning)
......@@ -335,6 +335,7 @@ class DLLEXPORTONLY BaseObject : public QObject {
/// Get the parent item ( 0 if rootitem )
BaseObject *parent();
const BaseObject *parent() const;
/// Set the parent pointer
void setParent(BaseObject* _parent);
......@@ -386,22 +387,22 @@ class DLLEXPORTONLY BaseObject : public QObject {
* Groups of groups are only suppurted via the other functions.
* @return Primary group of this object or -1
*/
int group();
int group() const;
/// Check if object is a group
bool isGroup();
bool isGroup() const;
/** Check if this item belongs to a group with this id
*
* @param _id id of the group
*/
bool isInGroup( int _id );
bool isInGroup( int _id ) const;
/** Check if this item belongs to a group with this name
*
* @param _name Name of the group
*/
bool isInGroup( QString _name );
bool isInGroup( QString _name ) const;
/** Get a vector of all Group ids this object belongs to ( this function omits the root object )
*/
......@@ -427,13 +428,13 @@ class DLLEXPORTONLY BaseObject : public QObject {
/// return the path to the object ( defaults to "." if unset )
QString path();
QString path() const;
/// set the path to the object.
void setPath(const QString &_path);
/// return the name of the object. The name defaults to NONAME if unset.
QString name( );
QString name( ) const;
/* set the name of the object. ( If you overwrite it, call BaseObject::setName(_name ) it in your funtion first)
......@@ -442,7 +443,7 @@ class DLLEXPORTONLY BaseObject : public QObject {
virtual void setName(QString _name );
/// return the filename of the object
QString filename();
QString filename() const;
/// set the filename for this object
void setFileName(const QString &_filename);
......@@ -515,7 +516,67 @@ class DLLEXPORTONLY BaseObject : public QObject {
QMap<QString, PerObjectData* > dataMap_;
/** @} */
/** @} */
//===========================================================================
/** @name Object Comment
* @{ */
//===========================================================================
public:
/** \brief Get comment for the specified key.
*
* If no comment with the specified exists, an empty
* one is created.
*/
QString &getCommentByKey(const QString &key) {
return commentsByKey_[key];
}
/** \brief Get comment for the specified key.
*
* If no comment with the specified exists, an empty comment
* is returned (but not inserted into the map).
*/
const QString getCommentByKey(const QString &key) const {
return commentsByKey_.value(key);
}
/** Returns true if a comment for the specified key exists, false otherwise. */
bool hasCommentForKey(const QString &key) const {
return commentsByKey_.contains(key);
}
/** Indicates whether any comment has been supplied for this object. */
bool hasComments() const {
return !commentsByKey_.empty();
}
/** Returns a reference to all comments. */
const QMap<QString, QString> &getAllComments() const {
return commentsByKey_;
}
/** Returns a flat, human readable representation of all comments. */
const QString getAllCommentsFlat() const {
QStringList result;
result.append(QString("BEGIN Comments for object \"%1\"").arg(name()));
for (QMap<QString, QString>::const_iterator it = commentsByKey_.begin(), it_end = commentsByKey_.end();
it != it_end; ++it) {
result.append(QString("%1: %2").arg(it.key(), it.value()));
}
result.append(QString("END Comments for object \"%1\"\n").arg(name()));
return result.join("\n");
}
private:
QMap<QString, QString> commentsByKey_;
/** @} */
};
......
......@@ -1251,7 +1251,7 @@ bool FileOFFPlugin::saveObject(int _id, QString _filename)
PolyMeshObject* polyObj = dynamic_cast<PolyMeshObject* >( object );
if (writeMesh(ofs, *polyObj->mesh())){
if (writeMesh(ofs, *polyObj->mesh(), *polyObj)){
emit log(LOGINFO, tr("Saved object to ") + _filename );
ofs.close();
return true;
......@@ -1267,7 +1267,7 @@ bool FileOFFPlugin::saveObject(int _id, QString _filename)
TriMeshObject* triObj = dynamic_cast<TriMeshObject* >( object );
if (writeMesh(ofs, *triObj->mesh())) {
if (writeMesh(ofs, *triObj->mesh(), *triObj)) {
emit log(LOGINFO, tr("Saved object to ") + _filename );
ofs.close();
return true;
......
......@@ -213,7 +213,7 @@ class FileOFFPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
/// Writer function
template< class MeshT >
bool writeMesh(std::ostream& _out, MeshT& _mesh );
bool writeMesh(std::ostream& _out, MeshT& _mesh, BaseObject &_baseObj);
/// Write binary mesh data to file
template< class MeshT >
......
......@@ -50,7 +50,7 @@
template< class MeshT >
bool FileOFFPlugin::writeMesh(std::ostream& _out, MeshT& _mesh ){
bool FileOFFPlugin::writeMesh(std::ostream& _out, MeshT& _mesh, BaseObject &_baseObj){
/*****************
* HEADER
......@@ -86,9 +86,10 @@ bool FileOFFPlugin::writeMesh(std::ostream& _out, MeshT& _mesh ){
* Comment
*/
OpenMesh::MPropHandleT<std::string> mp_comment;
if (_mesh.get_property_handle(mp_comment, "COMMENT")) {
if (_baseObj.hasComments()) {
_out << "# %% BEGIN OPENFLIPPER_COMMENT %%" << std::endl;
std::istringstream comment(_mesh.property(mp_comment));
std::istringstream comment(_baseObj.getAllCommentsFlat().toStdString());
std::string commentLine;
while (std::getline(comment, commentLine)) {
_out << "# " << commentLine << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment