How to insert a Node

In this tutorial i gonna describe step by step what you need to do to insert a node in a Projectconceptor Document 

At first we define the complete Node.

Therefore we create a BMessage wich will be our Node:

nodeMessage    = new BMessage(P_C_CLASS_TYPE);

P_C_CLASS_TYPE defines that this BMessage represent a node in the ProjectConceptor. Later there will also other kind of nodes like P_C_GROUP_TYPE

For every Node you need a Data "Section". In this "Section" you can store every Data wich should directly rendert to the Screen.  For example the name of the Node belongs there.

The Data Section is a normal BMessage wich is added to the node. So lets create the Data BMessage 

BMessage        *dataMessage    = new BMessage();

So we a field with the keystring "Name" to the DataContainer.

dataMessage->AddString("Name","My Cool Nodename");

after we finished here we can add the dataMessage to the node

nodeMessage->AddMessage("Data",dataMessage); 

Then we need the Rectangle wich describe the position and the dimension of the node, we just choose to have our node at the points 100,100 and the node should have a width and a height of 100 points:

nodeMessage->AddRect("Frame",BRect(100,100,200,200)); 

 To give your node a individual Design you should add also a fontMessage. In this Message you store alle necessary informations of the used font for this node. You also should create a patternMessage wich defines thinks like thickness of the line and so on. For more about the node structure just take a look a the node basics  or look up the tutorial how to insert a node.

 


Ok after we constructed our own node we now should insert it into the document :

To do this we need to send a command to the document:
//create the command to insert our node:

BMessage    *insertCommandMessage    = new BMessage(P_C_EXECUTE_COMMAND);

We define what Command Plugin should be used to process our command therefore we need to add a String with the KeyString "Command::Name". We want that the insert plugin is used, so we add the following Field to the command Message

insertCommandMessage->AddString("Command::Name","Insert");

then we add the pointer to the node o the command , wich should be insert.

insertCommandMessage->AddPointer("node",(void *)nodeMessage);

   

after creation of the Node we want that our new node is the only one wich is selected, so we add a subCommand: A Select Command:

//first create the BMessage

BMessage    *selectMessage    = new BMessage(P_C_EXECUTE_COMMAND);

//this is command shoud be processed by the Select Command  Plugin

selectMessage->AddString("Command::Name","Select");

//Thell the selectCommand Plugin that it should first deselect all Nodes  

selectMessage->AddBool("deselect",deselect);

//add a Pointer to the Node(s) wich should be selected
selectMessage->AddPointer("node",(void *)nodeMessage);

// add this selectCommand as a SubCommand to the insertcommand
insertCommandMessage->AddMessage("PCommand::subPCommand",selectMessage);

OK we are done! Congratulations we have everything prepared to insert a node in a projectconceptor document, now we only need to send it to the document. This could done like this(doc is a pointer to the document where you want to insert the node):  

 BMessenger *sentTo                = new BMessenger(doc);
sentTo->SendMessage(insertCommandMessageb);