Skip to content
Permalink
Browse files

prepare view provider for undo/redo

  • Loading branch information...
wwmayer committed Jun 18, 2016
1 parent 62a8828 commit f0e00311cdcbd6d5d71105c0a37261ba7d321197
@@ -106,6 +106,7 @@
#include "MaterialObject.h"
#include "MaterialPy.h"
#include "Expression.h"
#include "Transactions.h"

// If you stumble here, run the target "BuildExtractRevision" on Windows systems
// or the Python script "SubWCRev.py" on Linux based systems which builds
@@ -1133,6 +1134,7 @@ void Application::initTypes(void)
App ::PropertyExpressionEngine ::init();

// Document classes
App ::TransactionalObject ::init();
App ::DocumentObject ::init();
App ::GeoFeature ::init();
App ::FeatureTest ::init();
@@ -1173,6 +1175,9 @@ void Application::initTypes(void)
App ::BooleanExpression ::init();
App ::RangeExpression ::init();

// register transaction type
new App::TransactionProducer<TransactionDocumentObject>
(DocumentObject::getClassTypeId());
}

void Application::initConfig(int argc, char ** argv)
@@ -111,6 +111,7 @@ SET(Document_CPP_SRCS
OriginFeature.cpp
Range.cpp
Transactions.cpp
TransactionalObject.cpp
VRMLObject.cpp
MaterialObject.cpp
MergeDocuments.cpp
@@ -143,6 +144,7 @@ SET(Document_HPP_SRCS
OriginFeature.h
Range.h
Transactions.h
TransactionalObject.h
VRMLObject.h
MaterialObject.h
MergeDocuments.h
@@ -820,7 +820,7 @@ void Document::onChanged(const Property* prop)
}
}

void Document::onBeforeChangeProperty(const DocumentObject *Who, const Property *What)
void Document::onBeforeChangeProperty(const TransactionalObject *Who, const Property *What)
{
if (d->activeUndoTransaction && !d->rollback)
d->activeUndoTransaction->addObjectChange(Who,What);
@@ -2050,8 +2050,6 @@ void Document::remObject(const char* sName)
if (d->activeUndoTransaction) {
// in this case transaction delete or save the object
d->activeUndoTransaction->addObjectNew(pos->second);
// set name cache false
//pos->second->pcNameInDocument = 0;
}
else
// if not saved in undo -> delete object
@@ -2092,21 +2090,19 @@ void Document::_remObject(DocumentObject* pcObject)
pcObject->StatusBits.reset (ObjectStatus::Delete); // Unset the bit to be on the safe side

//remove the tip if needed
if(Tip.getValue() == pcObject) {
if (Tip.getValue() == pcObject) {
Tip.setValue(nullptr);
TipName.setValue("");
}

// do no transactions if we do a rollback!
if(!d->rollback){
if (!d->rollback) {
// Undo stuff
if (d->activeUndoTransaction)
d->activeUndoTransaction->addObjectNew(pcObject);
}
// remove from map
d->objectMap.erase(pos);
//// set name cache false
//pcObject->pcNameInDocument = 0;

for (std::vector<DocumentObject*>::iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) {
if (*it == pcObject) {
@@ -46,6 +46,7 @@ namespace Base {

namespace App
{
class TransactionalObject;
class DocumentObject;
class DocumentObjectExecReturn;
class Document;
@@ -308,9 +309,10 @@ class AppExport Document : public App::PropertyContainer

friend class Application;
/// because of transaction handling
friend class TransactionalObject;
friend class DocumentObject;
friend class Transaction;
friend class TransactionObject;
friend class TransactionDocumentObject;

/// Destruction
virtual ~Document();
@@ -329,7 +331,7 @@ class AppExport Document : public App::PropertyContainer

void onChanged(const Property* prop);
/// callback from the Document objects before property will be changed
void onBeforeChangeProperty(const DocumentObject *Who, const Property *What);
void onBeforeChangeProperty(const TransactionalObject *Who, const Property *What);
/// callback from the Document objects after property was changed
void onChangedProperty(const DocumentObject *Who, const Property *What);
/// helper which Recompute only this feature
@@ -30,17 +30,17 @@

#include "Document.h"
#include "DocumentObject.h"
#include "DocumentObjectPy.h"
#include "DocumentObjectGroup.h"
#include "PropertyLinks.h"
#include "PropertyExpressionEngine.h"
#include <App/DocumentObjectPy.h>
#include <boost/signals/connection.hpp>
#include <boost/bind.hpp>

using namespace App;


PROPERTY_SOURCE(App::DocumentObject, App::PropertyContainer)
PROPERTY_SOURCE(App::DocumentObject, App::TransactionalObject)

DocumentObjectExecReturn *DocumentObject::StdReturn = 0;

@@ -123,6 +123,18 @@ const char *DocumentObject::getNameInDocument(void) const
return pcNameInDocument->c_str();
}

bool DocumentObject::isAttachedToDocument() const
{
return (pcNameInDocument != 0);
}

const char* DocumentObject::detachFromDocument()
{
const std::string* name = pcNameInDocument;
pcNameInDocument = 0;
return name ? name->c_str() : 0;
}

std::vector<DocumentObject*> DocumentObject::getOutList(void) const
{
std::vector<Property*> List;
@@ -231,7 +243,7 @@ void DocumentObject::onBeforeChange(const Property* prop)
oldLabel = Label.getStrValue();

if (_pDoc)
_pDoc->onBeforeChangeProperty(this,prop);
onBeforeChangeProperty(_pDoc, prop);
}

/// get called by the container when a Property was changed
@@ -24,7 +24,7 @@
#ifndef APP_DOCUMENTOBJECT_H
#define APP_DOCUMENTOBJECT_H

#include <App/PropertyContainer.h>
#include <App/TransactionalObject.h>
#include <App/PropertyStandard.h>
#include <App/PropertyLinks.h>
#include <App/PropertyExpressionEngine.h>
@@ -76,7 +76,7 @@ class AppExport DocumentObjectExecReturn

/** Base class of all Classes handled in the Document
*/
class AppExport DocumentObject: public App::PropertyContainer
class AppExport DocumentObject: public App::TransactionalObject
{
PROPERTY_HEADER(App::DocumentObject);

@@ -95,6 +95,8 @@ class AppExport DocumentObject: public App::PropertyContainer

/// returns the name which is set in the document for this object (not the name property!)
const char *getNameInDocument(void) const;
virtual bool isAttachedToDocument() const;
virtual const char* detachFromDocument();
/// gets the document in which this Object is handled
App::Document *getDocument(void) const;

@@ -0,0 +1,50 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/


#include "PreCompiled.h"

#ifndef _PreComp_
#endif

#include <Base/Writer.h>

#include "Document.h"
#include "TransactionalObject.h"

using namespace App;


PROPERTY_SOURCE_ABSTRACT(App::TransactionalObject, App::PropertyContainer)

TransactionalObject::TransactionalObject(void)
{
}

TransactionalObject::~TransactionalObject(void)
{
}

void TransactionalObject::onBeforeChangeProperty(Document *doc, const Property *prop)
{
doc->onBeforeChangeProperty(this, prop);
}
@@ -0,0 +1,55 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/


#ifndef APP_TRANSACTIONALOBJECT_H
#define APP_TRANSACTIONALOBJECT_H

#include <App/PropertyContainer.h>

namespace App
{

class Document;
class TransactionObject;

/** Base class of transactional objects
*/
class AppExport TransactionalObject : public App::PropertyContainer
{
PROPERTY_HEADER(App::TransactionalObject);

public:
/// Constructor
TransactionalObject(void);
virtual ~TransactionalObject();
virtual bool isAttachedToDocument() const = 0;
virtual const char* detachFromDocument() = 0;

protected:
void onBeforeChangeProperty(Document *doc, const Property *prop);
};

} //namespace App


#endif // APP_TRANSACTIONALOBJECT_H
Oops, something went wrong.

0 comments on commit f0e0031

Please sign in to comment.
You can’t perform that action at this time.