📄 v4commandpanel.cpp
字号:
/* V4CommandPanel.cpp Panel allowing to choose an action for a given frame in the time line*/#include "safe_include.h"#include "V4CommandPanel.h"#include "V4StudioFrame.h"#include "V4Node.h"// !! order matters !!, index will become the command id// when command has no string, it is not available// see v4_scenegraph_vrml.hwxString cmdNames[] = { wxT(""), // GF_SG_SCENE_REPLACE wxT("Replace Node"), // GF_SG_NODE_REPLACE wxT("Replace Field"), // GF_SG_FIELD_REPLACE wxT(""), // GF_SG_INDEXED_REPLACE wxT(""), // GF_SG_ROUTE_REPLACE wxT("Delete Node"), // GF_SG_NODE_DELETE wxT(""), // GF_SG_INDEXED_DELETE wxT(""), // GF_SG_ROUTE_DELETE wxT("Insert Node"), // GF_SG_NODE_INSERT wxT("") // GF_SG_INDEXED_INSERT // TODO : to complete };// Events tableBEGIN_EVENT_TABLE(V4CommandPanel, wxPanel) EVT_PAINT(V4CommandPanel::OnPaint) EVT_COMBOBOX(cmbCommandID, V4CommandPanel::OnCommandCombo) EVT_COMBOBOX(cmbFieldID, V4CommandPanel::OnFieldCombo) EVT_BUTTON(CreateID, V4CommandPanel::OnCreateCommand)END_EVENT_TABLE()// ConstructorV4CommandPanel::V4CommandPanel(V4StudioFrame * parent_) : wxPanel(parent_, -1), // tabstabs(this, -1), tabView(&tabs, -1), tabAdd(&tabs, -1),// add PagecmbCommands(&tabAdd, cmbCommandID, ""),lblCommands(&tabAdd, -1, "Action :"),cmbNodes(&tabAdd, -1, ""),lblNodes(&tabAdd, -1, "Node :"), cmbFields(&tabAdd ,cmbFieldID, ""),lblFields(&tabAdd, -1, "Field :"),txtField(&tabAdd, -1, ""),btnCreate(&tabAdd, CreateID, "Create"),// view PagecmbListCommands(&tabView, -1),txtDesc(&tabView, -1),btnDelete(&tabView, -1, "Delete"){ parent = parent_; // disposition // global sizerTabs = new wxBoxSizer(wxHORIZONTAL); sizerTabs->Add(&tabs, 1, wxEXPAND); tabs.AddPage(&tabView, "View"); tabs.AddPage(&tabAdd, "Add"); // Add Page sizerAdd = new wxBoxSizer(wxVERTICAL); // up = combobox, middle = differs with the command, bottom = buttons sizerU = new wxBoxSizer(wxHORIZONTAL); // up sizerM = new wxBoxSizer(wxVERTICAL); // middle sizerD = new wxBoxSizer(wxHORIZONTAL); // bottom szSelectNode = new wxBoxSizer(wxHORIZONTAL); szSelectField = new wxBoxSizer(wxHORIZONTAL); szTxtField = new wxBoxSizer(wxHORIZONTAL); sizerAdd->Add(sizerU, 1, wxEXPAND); sizerAdd->Add(sizerM, 3, wxEXPAND); sizerAdd->Add(sizerD, 1, wxEXPAND); sizerU->Add(&lblCommands, 1, wxEXPAND | wxALL, 5); sizerU->Add(&cmbCommands, 3, wxEXPAND | wxALL, 2); szSelectField->Add(&lblFields, 1, wxEXPAND | wxALL, 5); szSelectField->Add(&cmbFields, 2, wxEXPAND | wxALL, 2); szSelectNode->Add(&lblNodes, 1, wxEXPAND | wxALL, 5); szSelectNode->Add(&cmbNodes, 2, wxEXPAND | wxALL, 2); szTxtField->Add(&txtField, 1, wxEXPAND | wxALL, 5); sizerD->Add(&btnCreate, 1, wxEXPAND | wxALL, 3); tabAdd.SetSizer(sizerAdd); // View Page sizerView = new wxBoxSizer(wxVERTICAL); sizerUp = new wxBoxSizer(wxHORIZONTAL); sizerDown = new wxBoxSizer(wxHORIZONTAL); sizerView->Add(sizerUp, 0, wxEXPAND); sizerView->Add(sizerDown, 4, wxEXPAND); sizerUp->Add(&cmbListCommands, 2, wxEXPAND | wxALL, 2); sizerUp->Add(&btnDelete, 1, wxEXPAND | wxALL, 2); sizerDown->Add(&txtDesc, 1, wxEXPAND); tabView.SetSizer(sizerView); // global SetSizer(sizerTabs); //Layout(); ShowFieldSizer(false); ShowNodeSizer(false); txtField.Show(false);}// DestructorV4CommandPanel::~V4CommandPanel() { delete szSelectNode; delete szSelectField; delete szTxtField;};/************************//* Events *//************************/// OnPaint eventvoid V4CommandPanel::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); dc.BeginDrawing(); // draws a seperator line on the left border int w,h; this->GetSize(&w, &h); dc.DrawLine(0, 0, 0, h); dc.EndDrawing();}// OnCommandCombo -- command combo box selection has changedvoid V4CommandPanel::OnCommandCombo(wxCommandEvent &event) { // retrieves the command id u32 command = (u32) cmbCommands.GetClientData(cmbCommands.GetSelection()); // retrieves the current node GF_Node * node = GetCurrentNode(); if (! IsCommandValidForNode(command, node)) { cmbCommands.SetSelection(-1); command = (u32) -1; } // shows or hides components switch (command) { case GF_SG_FIELD_REPLACE: { ShowNodeSizer(false); ShowFieldSizer(true); break; } case GF_SG_NODE_REPLACE: case GF_SG_NODE_INSERT: { ShowFieldSizer(false); ShowNodeSizer(true); break; } case GF_SG_NODE_DELETE: default : { ShowFieldSizer(false); ShowNodeSizer(false); } }}// OnFieldCombo -- field combo box selection has changedvoid V4CommandPanel::OnFieldCombo(wxCommandEvent &event) { // if no selection exits u32 sel = cmbFields.GetSelection(); if (sel == wxNOT_FOUND) return; // gets selected node in the timeline GF_Node * node = GetCurrentNode(); if (!node) return; GF_FieldInfo field; gf_node_get_field(node, sel, &field); // show or hides elements depending on the type of the field we will modify if ( (field.fieldType == GF_SG_VRML_SFNODE) || (field.fieldType == GF_SG_VRML_MFNODE) ) { sizerM->Detach(szTxtField); txtField.Show(false); ShowNodeSizer(true); } else { sizerM->Detach(szTxtField); sizerM->Add(szTxtField, 2, wxEXPAND); txtField.Show(true); }}// OnCreateCommand -- creates a command with the option from the UIvoid V4CommandPanel::OnCreateCommand(wxCommandEvent &event) { // verifies that there is a valid command value on cmbCommands u32 sel = cmbCommands.GetSelection(); if (sel == wxNOT_FOUND) return; // gets data from the UI u32 tag = (u32) cmbCommands.GetClientData(sel); GF_Node * node = GetCurrentNode(); // Creates the new command - REQUIRES registering the node GF_Command * c = gf_sg_command_new(parent->GetV4SceneManager()->GetSceneGraph(), tag); gf_node_register(node, NULL); c->node = node; // !! the node have to be registered if command is validated bool succeed = false;; // performs various initialization depending on the command tag switch (tag) { case GF_SG_NODE_REPLACE: { // TODO : not implemented yet because il would even replace the nodes in the dictionnary break; } case GF_SG_FIELD_REPLACE: { // verifies that a valid field is selected u32 selF = cmbFields.GetSelection(); if (selF == wxNOT_FOUND) break; // gets the field GF_FieldInfo field; gf_node_get_field(node, (u32)cmbFields.GetClientData(selF), &field); GF_CommandField * cmdField = gf_sg_command_field_new(c); // if failure, will be freed with freeing the command cmdField->fieldIndex = field.fieldIndex; cmdField->fieldType = field.fieldType; // fills the GF_CommandField structures with data depending on the field type switch (field.fieldType) { case GF_SG_VRML_SFNODE: { // get the node we will use as a replacement u32 selN = cmbNodes.GetSelection(); if (selN == wxNOT_FOUND) break; cmdField->new_node = (GF_Node *) cmbNodes.GetClientData(selN); // TODO : why is the 2nd line necessary ? cmdField->field_ptr = &cmdField->new_node; succeed = true; break; } case GF_SG_VRML_MFNODE: { break; } // field is not a node field default: { wxString s = txtField.GetValue(); if (s.IsEmpty()) break; GF_FieldInfo dummy; dummy.far_ptr = gf_sg_vrml_field_pointer_new(field.fieldType); dummy.fieldType = field.fieldType; parent->GetFieldView()->SetFieldValue(dummy, &s, 0); // TODO : check the zero cmdField->field_ptr = dummy.far_ptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -