Beispiel #1
0
void
Project::Load(wxWindow *parent, MenuState *menu, const wxString& filename)
{
	wxString type = GetProjectType(filename);
	New(parent, menu, type);
	wxFileInputStream fis(filename);
	int first = fis.Peek();
	if (first == 0x1b)
	{
		// Binary format.

		fis.GetC();
		LuaInputStream lis(&fis);
		l_instance->LoadBinary(lis);
	}
	else
	{
		// XML format.
		l_instance->LoadXML(fis);
	}
	// Clear Undo data of all panels.
	size_t count = l_instance->GetPageCount();
	for (size_t index = 0; index < count; index++)
	{
		Panel *panel = (Panel *)l_instance->GetPage(index);
		panel->GetUndoerCtrl()->Clear();
		panel->GetGraphCtrl()->GraphCanvas::Redraw(true);
		panel->GetGraphCtrl()->GenerateCode();
	}
}
Beispiel #2
0
int
Shader::ConfirmSave()
{
  Project* project  = Project::GetProject();
  bool     modified = false;
 
  if (project != 0)
  {
    int count = (int)project->GetPageCount();
    for (int index = 0; index < count; index++)
    {
      Panel*  panel = (Panel *)project->GetPage(index);
      modified      = modified || panel->GetUndoerCtrl()->IsDirty();
    }
  }

	if (modified)
	{
		wxString message = wxT("Save changes to ");
		if (m_FileName.IsEmpty())
		{
			message.Append(wxT("(untitled)"));
		}
		else
		{
			message.Append(m_FileName);
		}
		message.Append('?');
		wxMessageDialog dialog(this, message, wxT("Confirm"), wxYES_NO | wxCANCEL);
		int choice = dialog.ShowModal();
		if (choice == wxID_YES)
		{
			return Save();
		}
		return choice;
	}
	return wxID_YES;
}
Beispiel #3
0
void
Shader::OnCommand(wxCommandEvent& evt)
{
	Project *project = Project::GetProject();
	Panel *panel;
	Undoer *undoer;
	Graph *graph;
	if (project != NULL)
	{
		panel = project->GetPanel();
		if (panel != NULL)
		{
			undoer = panel->GetUndoerCtrl();
			graph = panel->GetGraphCtrl();
		}
	}
	switch (evt.GetId())
	{
	case wxID_OPEN:
		Open();
		break;
	case wxID_SAVE:
		Save();
		break;
	case wxID_SAVEAS:
		SaveAs();
		break;
	case wxID_EXIT:
		Close(false);
		break;
	case wxID_UNDO:
		undoer->Undo();
		break;
	case wxID_REDO:
		undoer->Redo();
		break;
	case wxID_CUT:
		graph->Cut();
		break;
	case wxID_COPY:
		graph->Copy();
		break;
	case wxID_PASTE:
		graph->Paste();
		break;
	case wxID_DUPLICATE:
		graph->Duplicate();
		break;
	case wxID_GROUP:
		graph->GroupNodes();
		break;
	case wxID_UNGROUP:
		graph->UngroupNodes();
		break;
	case wxID_SAVEGROUP:
		graph->SaveGroup();
		break;
	case wxID_COPYMETAFILE:
		graph->CopyAsMetafile();
		break;
	case wxID_CONFIGURE:
		project->Configure();
		break;
	case wxID_RELOADLIBS:
		//project->ReloadLibs();
		break;
	}
}
Beispiel #4
0
void
Project::New(wxWindow *parent, MenuState *state, const wxString& type)
{
	if (l_instance != NULL)
	{
		DESTROY(l_instance);
	}
	l_instance = NEW(Project, (parent, type));
	// Load the XML project description.
	Debug::Printf(TXT("Parsing \"%s\".\n"), l_Types[type].c_str());
	wxXmlDocument xml;
	if (!xml.Load(l_Types[type]))
	{
		THROW(TXT("Couldn't parse the XML file."));
	}
	if (xml.GetRoot()->GetName() != wxT("project"))
	{
		THROW(TXT("Root node isn't <project>."));
	}

	//wxArrayString groups = NodeLibrary::AddUserNodes();
	//wxString grpfile(g_FragmentShaderLibPath);
	//grpfile.Append(wxT("nodes\\user.xml"));
	//wxArrayString groups = NodeLibrary::Add(grpfile);

	wxXmlNode *child = xml.GetRoot()->GetChildren();
	while (child != 0)
	{
		if (child->GetType() == wxXML_COMMENT_NODE)
		{
			child = child->GetNext();
			continue;
		}
		if (child->GetName() == wxT("panel"))
		{
			wxString name;
			if (!child->GetPropVal(wxT("name"), &name))
			{
				THROW(TXT("Couldn't find attribute 'name' in element <panel>."));
			}
			Panel *panel = NEW(Panel, (l_instance, state->Clone()));
			panel->Freeze();
			l_instance->AddPage(panel, name);
			Debug::Printf(TXT("Panel \"%s\" (%p) created.\n"), name.c_str(), panel);
			wxXmlNode *child2 = child->GetChildren();
      /*
			for (size_t i = 0; i < groups.GetCount(); i++)
			{
				panel->AddToTree(groups[i]);
				Debug::Printf(TXT("Group \"%s\" added to panel %p.\n"), groups[i].c_str(), panel);
			}
      */
			while (child2 != 0)
			{
				if (child2->GetType() == wxXML_COMMENT_NODE)
				{
					child2 = child2->GetNext();
					continue;
				}
				if (child2->GetName() == wxT("add-library"))
				{
					wxString path;
					if (!child2->GetPropVal(wxT("path"), &path))
					{
						THROW(TXT("Couldn't find attribute 'path' in element <add-library>."));
					}
					panel->LoadLibrary(path);
					Debug::Printf(TXT("Library \"%s\" added to panel %p.\n"), path, panel);
				}
				else if (child2->GetName() == wxT("add-node"))
				{
					wxString type;
					if (!child2->GetPropVal(wxT("type"), &type))
					{
						THROW(TXT("Couldn't find attribute 'type' in element <add-node>."));
					}
					wxString deletable = child2->GetPropVal(wxT("deletable"), wxT("false"));
					panel->AddNode(type, deletable == wxT("true"));
					Debug::Printf(TXT("Node \"%s\" added to panel %p.\n"), type.c_str(), panel);
				}
				else
				{
					Debug::Printf(TXT("\tInvalid element <%s> in <panel>.\n"), child2->GetName().c_str());
				}
				child2 = child2->GetNext();
			}
			panel->Thaw();
		}
		else
		{
			Debug::Printf(TXT("\tInvalid element <%s> in <project>.\n"), child->GetName().c_str());
		}
		child = child->GetNext();
	}
	// Delete the menu state (it has been cloned for each panel.)
	DESTROY(state);
	// Load the panels configuration.
	l_instance->LoadConfig();
	// Clear Undo data of all panels.
	size_t count = l_instance->GetPageCount();
	for (size_t index = 0; index < count; index++)
	{
		Panel *panel = (Panel *)l_instance->GetPage(index);
		panel->GetUndoerCtrl()->Clear();
	}
}