I understand that a single instance of this class is created for each autocad document created and that the purpose is to add to the CDocData class any "drawing" related information I may want to, but........ is this class automatically persisted by the document manager? If it isn't, than why not just used to NOD for document related data???
Any thoughts appreciated!
Mike B
Man-o-man, for the life of me, I cannot think of a single piece of data used in a cad system that would not need to be persisted. Anyone have any good examples?
Thanks Owen
Mike
@Anonymous wrote:
Anyone have any good examples?
Per-document data. Such as pointer to database reactor (class AcDbDatabaseReactor) to document database.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
The CDocData class is a class used to store your Document specific data.
What is document specific data? The best way to explain it is to show you some code and the results of running the code…
First, lets input an integer and have a static variable that offers a default value…
staticintdefaultValue = 0;
voidmyCmd()
{
TCHARprintBuffer[256];
_stprintf(printBuffer, _T("\nEnter value <%d> : "), defaultValue);
acedGetInt(printBuffer, &defaultValue);
}
If you load this code into AutoCAD and run it, it will first offer a default value of 0, and then offer any value you type in as the following default. If you create a new drawing, that default value is shown for each drawing.
Now to create some document specific data…
classCDocData {
public:
CDocData ()
{
defaultValue = 0;
};
CDocData (constCDocData &data)
{
defaultValue = data.defaultValue;
}
~CDocData () ;
intdefaultValue;
} ;
AcApDataManager<CDocData> DocVars ;
voidmyCmd()
{
TCHARprintBuffer[256];
_stprintf(printBuffer, _T("\nEnter value <%d> : "), DocVars.docData().defaultValue);
acedGetInt(printBuffer, &DocVars.docData().defaultValue);
}
If you load this code into AutoCAD and run it, it will first offer a default value of 0, and then offer any value you type in as the following default. However, this time, if you create a new drawing, you will be offered a 0 default and any value that you type in will be stored separately to any other document. Pretty cool.
As you can see this data is not persisted, and my example is very basic – where would this class really become useful? The answer is for document specific reactors, here’s an example..
classCDocData
{
public:
CDocData();
CDocData(constCDocData &data) ;
~CDocData();
asdkMyDatabaseReactor* m_pasdkMyDatabaseReactor;
};
//
// Implementation of the document data class.
//
CDocData::CDocData()
{
m_pasdkMyDatabaseReactor = NULL;
}
CDocData::CDocData(constCDocData &data)
{
m_pasdkMyDatabaseReactor = NULL;
}
CDocData::~CDocData()
{
if (m_pasdkMyDatabaseReactor) deletem_pasdkMyDatabaseReactor;
}
//
// setting up the reactor – now it is contained by the document data, don’t need to worry about it anymore
//
DocVars
.docData().m_pasdkMyDatabaseReactor = newasdkMyDatabaseReactor();
cuDoc()->database()->addReactor(DocVars.docData().m_pasdkMyDatabaseReactor);
Didn't even think of database reactors.
Thanks for the clear explanation and example.
Mike B