Skip to main content
Participating Frequently
June 11, 2008
Question

Persist custom data in document / Is ASB-CSB, Command the only way?

  • June 11, 2008
  • 3 replies
  • 549 views
I have a need to persist custom data set (PMString for now) in a document, say for example source URL. Basic Persist sample suggests using implementing suites and commands. I was wondering if there is a quick way of doing such a simple task. XMP may be?

Thanks
This topic has been closed for replies.

3 replies

Inspiring
June 12, 2008
Hi Carl,

I had not tested with debug version, so I didn't notice the assert.

But if you just want to set the value with no undoability, maybe what the assert suggest NOT to be done might be the right solution (that is BeginTransaction/EndTransaction).

Regarding undoability, I've found this in some CS1 code

>cmdXXX->SetUndoability(ICommand::kUndoNotRequired);

It might help.

Cheers,

J.
Participating Frequently
June 12, 2008
J,

Best answer I ever got. Thanks for taking time to write detailed response.

What you suggested does make sense. I implemented it in a plugin for ID CS3 and on executing iParamSerial->setParams() got following assert:

"Direct model change to database without transaction. Either process a command or call a utility or facade interface that does what you want, or implement your own cmd if none exist. Generally, DON'T just call IDataBase::BeginTransaction()/EndTransaction."

This also makes sense. I anticipated this earlier and thus asked for a utility or helper class. Anyway I have taken longer route and implemented ASB-CSB (probably which I could get by) and a command. Which is interesting because using command I get undo/redo support out of the box, which actually in this case I dont want. I am sure there is a trick to set undoability of command to false (need to read more).

Thanks again,
CG
Inspiring
June 11, 2008
Hi Carl,<br /><br />What you need is the header file : 'IWFPParamaSerial.h'<br /><br />>#include "VCPlugInHeaders.h"<br /><br />>#include "IPMUnknown.h"<br />#include "WFPID.h"<br /><br />>class IWFPParamSerial : public IPMUnknown<br />{<br />public : <br /> enum { kDefaultIID = IID_IWFPPARAMSERIAL };<br /> virtual void SetParams(const PMString &pmstrParams)=0;<br /> virtual void GetParams(PMString &pmstrParams) = 0;<br />};<br /><br />Then, the implementation :'IWFPParamaSerial.cpp'<br /><br />>#include "VCPlugInHeaders.h"<br />// Interface includes<br />#include "IWFPParamSerial.h"<br />#include "WFPID.h"<br />// General includes:<br />#include "CPMUnknown.h"<br />#include "K2Vector.h"<br />#include "IPMStream.h"<br /><br />>class WFPParamSerial : public CPMUnknown<IWFPParamSerial><br />{<br />public:<br /> /** Constructor. */<br /> WFPParamSerial(IPMUnknown* boss);<br /> /** Destructor. */<br /> ~WFPParamSerial(){};<br /> virtual void SetParams(const PMString &pmstrParams);<br /> virtual void GetParams(PMString &pmstrParams); <br /> void ReadWrite(IPMStream* stream, ImplementationID implementation);<br />private : <br /> PMString m_pstrParams;<br />};<br /><br />>CREATE_PERSIST_PMINTERFACE(WFPParamSerial, kWFPParamSerialImpl)<br /><br />>WFPParamSerial::WFPParamSerial(IPMUnknown* boss) : CPMUnknown<IWFPParamSerial>(boss)<br />{<br />}<br /><br />>void WFPParamSerial::SetParams(const PMString &pmstrParams)<br />{<br /> if (pmstrParams != m_pstrParams)<br /> {<br /> PreDirty();<br /> m_pstrParams = pmstrParams;<br /> }<br />}<br /><br />>void WFPParamSerial::GetParams(PMString &pmstrParams)<br />{<br /> pmstrParams = m_pstrParams;<br />}<br /><br />>void WFPParamSerial::ReadWrite(IPMStream* stream, ImplementationID implementation)<br />{<br /> m_pstrParams.ReadWrite(stream);<br />}<br /><br />Of course, in the 'WFPID.h', declarations for interface & implementation IDs :<br /><br />>DECLARE_PMID(kInterfaceIDSpace, IID_IWFPPARAMSERIAL, kWFPPrefix + 1)<br />DECLARE_PMID(kImplementationIDSpace, kWFPParamSerialImpl, kWFPPrefix + 6)<br /><br />In 'WFPFactory.h' :<br />>REGISTER_PMINTERFACE(kWFPParamSerialImpl, kWFPParamSerialImpl)<br /><br />And in 'WFP.fr', add it to relevant boss (<br /><br />>resource ClassDescriptionTable(kSDKDefClassDescriptionTableResourceID)<br />{{{<br />...<br />AddIn<br /> {<br /> kDocWorkspaceBoss,<br /> kInvalidClass,<br /> {<br /> IID_IWFPPARAMSERIAL, kWFPParamSerialImpl,<br /> }<br /> },<br />...<br />}}};<br /><br />Then when you have a IWorkSpace interface, you can set or get it :<br /><br />>InterfacePtr<IWorkspace> iDocWorkSpace(iDoc->GetDocWorkSpace(), UseDefaultIID());<br />if (!iDocWorkSpace) return;<br />InterfacePtr<IWFPParamSerial> iParamSerial(iDocWorkSpace, UseDefaultIID());<br />if (!iParamSerial) return;<br />PMString strParams;<br />iParamSerial->GetParams(strParams);<br /><br />HTH (and I forgot nothing :-)<br /><br />J.