Пример #1
0
Interaction::CommandResult* CCreateField::create(Visualization::Item* /*source*/, Visualization::Item* target,
	const QString& name, const QStringList& attributes)
{
	auto cl = dynamic_cast<OOModel::Class*> (target->node());
	Q_ASSERT(cl);

	auto f = new OOModel::Field();
	f->setTypeExpression(new OOModel::EmptyExpression());
	if (!name.isEmpty()) f->setName(name);

	// Set visibility
	if (attributes.first() == "private" ) f->setVisibility(OOModel::Visibility::PRIVATE);
	else if (attributes.first() == "protected" ) f->setVisibility(OOModel::Visibility::PROTECTED);
	else if (attributes.first() == "public" ) f->setVisibility(OOModel::Visibility::PUBLIC);
	else f->setVisibility(OOModel::Visibility::DEFAULT);

	// Set scope
	if (attributes.last() == "static") f->setStorageSpecifier(OOModel::StorageSpecifier::CLASS_VARIABLE);
	else f->setStorageSpecifier(OOModel::StorageSpecifier::INSTANCE_VARIABLE);

	cl->fields()->beginModification("create field");
	cl->fields()->append(f);
	cl->fields()->endModification();

	target->setUpdateNeeded(Visualization::Item::StandardUpdate);
	target->scene()->addPostEventAction(new Interaction::SetCursorEvent(target,
			(name.isEmpty() ? static_cast<Model::Node*>(f->nameNode()) : f->typeExpression()),
			Interaction::SetCursorEvent::CursorDefault, false));

	return new Interaction::CommandResult();
}
void namesOfNodes(points name[20])
{
	for(int i=0; i<20; i++)
	{
		Text nameNode(name[i].x,name[i].y-10,name[i].name);//name is imprinted just above the node
		nameNode.imprint();
	}
	
}
Пример #3
0
/** Changes the server's technical note
  *
  * The xml document should be saved after this call.
  *
  * \param v The new server's technical note
  *
  */
void RainbruRPG::Server::xmlServerConf::setTechNote(const std::string& v){
  TiXmlText nameNode(v.c_str());

  TiXmlNode* childNode = root->FirstChild( "TechnicalNote" );
  if (childNode){
    childNode->Clear();
    childNode->InsertEndChild(nameNode);
  }
 
}
Пример #4
0
void MainWindow::saveFile()
{
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("XML Files (*.xml)"));

    if(fileName != "")
    {
        TiXmlDocument doc;
        // Declaration
        TiXmlDeclaration declaration(std::string("1.0"), std::string(), std::string() );
        // InsertEndChild method uses deep copy
        doc.InsertEndChild( declaration );
        TiXmlElement project("project");
        TiXmlElement node("name");
        // Use TiXmlText to insert text body to an element
        // Covert QString back to std::string
        TiXmlText text(projectName.toStdString());
        node.InsertEndChild(text);
        project.InsertEndChild(node);

        // And all the HEES components
        QList<QGraphicsItem*> itemList = scene->items();
        for(int i=0;i<itemList.size();i++)
        {
            HEESGraphicsItem * item = dynamic_cast<HEESGraphicsItem *>(itemList[i]);
            if( item )
            {
                TiXmlElement comp("comp");
                switch(item->myType())
                {
                case SOURCE:
                    comp.SetAttribute("type","source");
                    break;
                case LOAD:
                    comp.SetAttribute("type","load");
                    break;
                case BANK:
                    comp.SetAttribute("type","bank");
                    break;
                case CTI:
                    comp.SetAttribute("type","cti");
                    break;
                case CONVERTER:
                    comp.SetAttribute("type","converter");
                    break;
                case MANAGER:
                    comp.SetAttribute("type","manager");
                    break;
                }

                comp.SetAttribute("x_pos", item->x());
                comp.SetAttribute("y_pos", item->y());

                TiXmlElement nameNode("name");
                text.SetValue(item->name.toStdString());
                nameNode.InsertEndChild(text);
                comp.InsertEndChild(nameNode);

                if(item->myType() == CONVERTER)
                {
                    TiXmlElement portANode("port_a");
                    text.SetValue(item->getPortAName().toStdString());
                    portANode.InsertEndChild(text);
                    comp.InsertEndChild(portANode);

                    TiXmlElement portBNode("port_b");
                    text.SetValue(item->getPortBName().toStdString());
                    portBNode.InsertEndChild(text);
                    comp.InsertEndChild(portBNode);
                }

                TiXmlElement derivedNode("derived");
                if(item->myType() != CTI)
                {
                    derivedNode.SetAttribute("type",item->derivedType.toStdString());
                }

                DerivedAttributes * attributes = item->myAttributes();
                for(int j=0; j<attributes->rowCount()-1; j++)
                {
                    TiXmlElement attributeNode(attributes->nameAt(j).toStdString());
                    text.SetValue(attributes->valueAt(j).toStdString());
                    attributeNode.InsertEndChild(text);
                    derivedNode.InsertEndChild(attributeNode);
                }

                comp.InsertEndChild(derivedNode);
                project.InsertEndChild(comp);
            }
        }

        // Add all the sensors
        for(int i=0;i<itemList.size();i++)
        {
            HEESGraphicsItem * item = dynamic_cast<HEESGraphicsItem *>(itemList[i]);
            if( item )
            {
                SensorList * sensorList = item->mySensors();
                for(int j=0; j<sensorList->size(); j++)
                {
                    TiXmlElement sensorNode("sensor");
                    sensorNode.SetAttribute("target", item->name.toStdString());
                    sensorNode.SetAttribute("property", sensorList->sensorAt(j).toStdString());
                    project.InsertEndChild(sensorNode);
                }
            }
        }

        // Add all the commands
        for(int i=0;i<commands.size();i++)
        {
            TiXmlElement cmdNode("cmd");
            Command * cmd = commands.commandAt(i);
            cmdNode.SetAttribute("time", cmd->time);
            cmdNode.SetAttribute("type", cmd->type.toStdString());
            if( !cmd->targetName.isEmpty() )
                cmdNode.SetAttribute("target", cmd->targetName.toStdString());
            if( !cmd->propertyName.isEmpty() )
            {
                TiXmlElement propertyNode(cmd->propertyName.toStdString());
                text.SetValue(cmd->propertyValue.toStdString());
                propertyNode.InsertEndChild(text);
                cmdNode.InsertEndChild(propertyNode);
            }
            project.InsertEndChild(cmdNode);
        }

        doc.InsertEndChild(project);

        if(!doc.SaveFile(fileName.toStdString()))
        {
            QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
        }
    }
}