Пример #1
0
void Xml::tag(const QString& name, QVariant data)
      {
      QString ename(name.split(' ')[0]);

      putLevel();
      switch(data.type()) {
            case QVariant::Bool:
            case QVariant::Char:
            case QVariant::Int:
            case QVariant::UInt:
                  *this << "<" << name << ">";
                  *this << data.toInt();
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::Double:
                  *this << "<" << name << ">";
                  *this << data.value<double>();
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::String:
                  *this << "<" << name << ">";
                  *this << xmlString(data.value<QString>());
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::Color:
                  {
                  QColor color(data.value<QColor>());
                  *this << QString("<%1 r=\"%2\" g=\"%3\" b=\"%4\"/>\n").arg(name).arg(color.red()).arg(color.green()).arg(color.blue());
                  }
                  break;
            case QVariant::Rect:
                  {
                  QRect r(data.value<QRect>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\" w=\"%4\" h=\"%5\"/>\n").arg(name).arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
                  }
                  break;
            case QVariant::RectF:
                  {
                  QRectF r(data.value<QRectF>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\" w=\"%4\" h=\"%5\"/>\n").arg(name).arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
                  }
                  break;
            case QVariant::PointF:
                  {
                  QPointF p(data.value<QPointF>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\"/>\n").arg(name).arg(p.x()).arg(p.y());
                  }
                  break;
            case QVariant::SizeF:
                  {
                  QSizeF p(data.value<QSizeF>());
                  *this << QString("<%1 w=\"%2\" h=\"%3\"/>\n").arg(name).arg(p.width()).arg(p.height());
                  }
                  break;
            default:
                  printf("Xml::tag: unsupported type %d\n", data.type());
                  // abort();
                  break;
            }
      }
Пример #2
0
void Xml::writeXml(const QString& name, QString s)
      {
      QString ename(name.split(' ')[0]);
      putLevel();
      for (int i = 0; i < s.size(); ++i) {
            ushort c = s.at(i).unicode();
            if (c < 0x20 && c != 0x09 && c != 0x0A && c != 0x0D)
                  s[i] = '?';
            }
      *this << "<" << name << ">";
      *this << s;
      *this << "</" << ename << ">\n";
      }
Пример #3
0
static int flagVariable(CellMLModelDefinition* d,const char* name, const wchar_t* typeString,
    std::vector<iface::cellml_services::VariableEvaluationType> vets,int& count, int& specificCount)
{
  if (! d->mCodeInformation)
  {
    std::cerr << "CellMLModelDefinition::flagVariable -- missing model?" << std::endl;
    return -1;
  }
  //std::cout << "setting variable '" << cv.second.c_str() << "' from component '" << cv.first.c_str() << "' as KNOWN" << std::endl;
  iface::cellml_api::Model* model = static_cast<iface::cellml_api::Model*>(d->mModel);
  iface::cellml_services::CodeInformation* cci= static_cast<iface::cellml_services::CodeInformation*>(d->mCodeInformation);
  iface::cellml_services::AnnotationSet* as = static_cast<iface::cellml_services::AnnotationSet*>(d->mAnnotations);
  RETURN_INTO_OBJREF(sv,iface::cellml_api::CellMLVariable,findLocalVariable(model,name));
  // check if source is already marked as known - what to do? safe to continue with no error
  RETURN_INTO_WSTRING(currentAnnotation,as->getStringAnnotation(sv,L"flag"));
  if (!currentAnnotation.empty())
  {
    if (currentAnnotation == typeString)
    {
      std::cout << "Already flagged same type, nothing to do." << std::endl;
      return 0;
    }
    else
    {
      std::cerr << "CellMLModelDefinition::flagVariable -- variable already flagged something else: "
          << name << std::endl;
      return -5;
    }
  }
  // find corresponding computation target
  RETURN_INTO_OBJREF(cti,iface::cellml_services::ComputationTargetIterator,cci->iterateTargets());
  iface::cellml_services::ComputationTarget* ct = NULL;
  while(1)
  {
    ct = cti->nextComputationTarget();
    if (ct == NULL) break;
    if (ct->variable() == sv)
    {
//      std::cout << "found a computation target for the source variable of the variable: "
//          << cv.first.c_str() << " / " << cv.second.c_str() << std::endl;
      break;
    }
    else
    {
      ct->release_ref();
      ct = NULL;
    }
  }
  if (!ct)
  {
    std::cerr << "CellMLModelDefinition::flagVariable -- unable get computation target for the source of variable: "
        << name << std::endl;
    return -5;
  }

  // check type of computation target and make sure compatible
  unsigned int i,compatible = 0;
  for (i=0;i<vets.size();i++)
  {
    if (ct->type() == vets[i])
    {
      compatible = 1;
      break;
    }
  }
  if (compatible)
  {
    as->setStringAnnotation(sv,L"flag",typeString);
    std::wstring ename(L"OC_");
    ename += typeString;
    as->setStringAnnotation(sv,L"array",ename.c_str());
    as->setStringAnnotation(ct->variable(),L"array_index",formatNumber(specificCount).c_str());
    specificCount++;
    count++;
  }
  else
  {
    std::cerr << "CellMLModelDefinition::flagVariable -- computation target for variable: "
        << name << "; is the wrong type to be flagged" << std::endl;
    std::cerr << "Computation target for this source variable is: ";
    switch (ct->type())
    {
    case iface::cellml_services::CONSTANT:
      std::cerr << "CONSTANT";
      break;
    case iface::cellml_services::VARIABLE_OF_INTEGRATION:
      std::cerr << "VARIABLE_OF_INTEGRATION";
      break;
    case iface::cellml_services::STATE_VARIABLE:
      std::cerr << "STATE_VARIABLE";
      break;
    case iface::cellml_services::PSEUDOSTATE_VARIABLE:
      std::cerr << "PSEUDOSTATE_VARIABLE";
      break;
    case iface::cellml_services::ALGEBRAIC:
      std::cerr << "ALGEBRAIC";
      break;
    case iface::cellml_services::LOCALLY_BOUND:
      std::cerr << "LOCALLY_BOUND";
      break;
    case iface::cellml_services::FLOATING:
      std::cerr << "FLOATING";
      break;
    default:
      std::cerr << "Invalid";
    }
    std::cerr << std::endl;
    ct->release_ref();
    return -5;
  }
  ct->release_ref();
  return 0;
}
Пример #4
0
void Xml::tag(const QString& name, QVariant data)
      {
      QString ename(name.split(' ')[0]);

      putLevel();
      switch(data.type()) {
            case QVariant::Bool:
            case QVariant::Char:
            case QVariant::Int:
            case QVariant::UInt:
                  *this << "<" << name << ">";
                  *this << data.toInt();
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::Double:
                  *this << "<" << name << ">";
                  *this << data.value<double>();
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::String:
                  *this << "<" << name << ">";
                  *this << xmlString(data.value<QString>());
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::Color:
                  {
                  QColor color(data.value<QColor>());
                  *this << QString("<%1 r=\"%2\" g=\"%3\" b=\"%4\" a=\"%5\"/>\n")
                     .arg(name).arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha());
                  }
                  break;
            case QVariant::Rect:
                  {
                  const QRect& r(data.value<QRect>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\" w=\"%4\" h=\"%5\"/>\n").arg(name).arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
                  }
                  break;
            case QVariant::RectF:
                  {
                  const QRectF& r(data.value<QRectF>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\" w=\"%4\" h=\"%5\"/>\n").arg(name).arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
                  }
                  break;
            case QVariant::PointF:
                  {
                  const QPointF& p(data.value<QPointF>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\"/>\n").arg(name).arg(p.x()).arg(p.y());
                  }
                  break;
            case QVariant::SizeF:
                  {
                  const QSizeF& p(data.value<QSizeF>());
                  *this << QString("<%1 w=\"%2\" h=\"%3\"/>\n").arg(name).arg(p.width()).arg(p.height());
                  }
                  break;
            default: {
                  const char* type = data.typeName();
                  if (strcmp(type, "Ms::Spatium") == 0) {
                        *this << "<" << name << ">";
                        *this << data.value<Spatium>().val();
                        *this << "</" << ename << ">\n";
                        }
                  else if (strcmp(type, "Ms::Fraction") == 0) {
                        const Fraction& f = data.value<Fraction>();
                        *this << QString("<%1>%2/%3</%1>\n").arg(name).arg(f.numerator()).arg(f.denominator());
                        }
                  else {
                        qFatal("Xml::tag: unsupported type %d %s", data.type(), type);
                        }
                  }
                  break;
            }
      }
Пример #5
0
static int MainProcess(
    const string& EditName,
    const string& ViewName,
    const string& DestName1,
    const string& DestName2,
    int StartLine,
    int StartChar
)
{
		SCOPED_ACTION(ChangePriority)(THREAD_PRIORITY_NORMAL);
		FarColor InitAttributes={};
		console.GetTextAttributes(InitAttributes);
		SetRealColor(colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN));

		string ename(EditName),vname(ViewName), apanel(DestName1),ppanel(DestName2);
		if (ConfigProvider().ShowProblems())
		{
			ename.clear();
			vname.clear();
			StartLine = StartChar = -1;
			apanel = Global->Opt->ProfilePath;
			ppanel = Global->Opt->LocalProfilePath;
		}

		if (!ename.empty() || !vname.empty())
		{
			Global->OnlyEditorViewerUsed = true;

			_tran(SysLog(L"create dummy panels"));
			Global->CtrlObject->CreateDummyFilePanels();
			Global->WindowManager->PluginCommit();

			Global->CtrlObject->Plugins->LoadPlugins();
			Global->CtrlObject->Macro.LoadMacros(true, true);

			if (!ename.empty())
			{
				const auto ShellEditor = FileEditor::create(ename, CP_DEFAULT, FFILEEDIT_CANNEWFILE | FFILEEDIT_ENABLEF6, StartLine, StartChar);
				_tran(SysLog(L"make shelleditor %p",ShellEditor));

				if (!ShellEditor->GetExitCode())  // ????????????
				{
					Global->WindowManager->ExitMainLoop(0);
				}
			}
			// TODO: Этот else убрать только после разборок с возможностью задавать несколько /e и /v в ком.строке
			else if (!vname.empty())
			{
				const auto ShellViewer = FileViewer::create(vname, true);

				if (!ShellViewer->GetExitCode())
				{
					Global->WindowManager->ExitMainLoop(0);
				}

				_tran(SysLog(L"make shellviewer, %p",ShellViewer));
			}

			Global->WindowManager->EnterMainLoop();
		}
		else
		{
			int DirCount=0;

			// воспользуемся тем, что ControlObject::Init() создает панели
			// юзая Global->Opt->*

			const auto& SetupPanel = [&](bool active)
			{
				++DirCount;
				string strPath = active? apanel : ppanel;
				if (os::fs::is_file(strPath))
				{
					CutToParent(strPath);
				}

				bool Root = false;
				const auto Type = ParsePath(strPath, nullptr, &Root);
				if(Root && (Type == root_type::drive_letter || Type == root_type::unc_drive_letter || Type == root_type::volume))
				{
					AddEndSlash(strPath);
				}

				auto& CurrentPanelOptions = (Global->Opt->LeftFocus == active)? Global->Opt->LeftPanel : Global->Opt->RightPanel;
				CurrentPanelOptions.m_Type = static_cast<int>(panel_type::FILE_PANEL);  // сменим моду панели
				CurrentPanelOptions.Visible = true;     // и включим ее
				CurrentPanelOptions.Folder = strPath;
			};

			if (!apanel.empty())
			{
				SetupPanel(true);

				if (!ppanel.empty())
				{
					SetupPanel(false);
				}
			}

			// теперь все готово - создаем панели!
			Global->CtrlObject->Init(DirCount);

			// а теперь "провалимся" в каталог или хост-файл (если получится ;-)
			if (!apanel.empty())  // активная панель
			{
				const auto ActivePanel = Global->CtrlObject->Cp()->ActivePanel();
				const auto AnotherPanel = Global->CtrlObject->Cp()->PassivePanel();

				if (!ppanel.empty())  // пассивная панель
				{
					FarChDir(AnotherPanel->GetCurDir());

					if (IsPluginPrefixPath(ppanel))
					{
						AnotherPanel->Parent()->SetActivePanel(AnotherPanel);

						execute_info Info;
						Info.Command = ppanel;

						Global->CtrlObject->CmdLine()->ExecString(Info);
						ActivePanel->Parent()->SetActivePanel(ActivePanel);
					}
					else
					{
						const auto strPath = PointToName(ppanel);

						if (!strPath.empty())
						{
							if (AnotherPanel->GoToFile(strPath))
								AnotherPanel->ProcessKey(Manager::Key(KEY_CTRLPGDN));
						}
					}
				}

				FarChDir(ActivePanel->GetCurDir());

				if (IsPluginPrefixPath(apanel))
				{
					execute_info Info;
					Info.Command = apanel;

					Global->CtrlObject->CmdLine()->ExecString(Info);
				}
				else
				{
					const auto strPath = PointToName(apanel);

					if (!strPath.empty())
					{
						if (ActivePanel->GoToFile(strPath))
							ActivePanel->ProcessKey(Manager::Key(KEY_CTRLPGDN));
					}
				}

				// !!! ВНИМАНИЕ !!!
				// Сначала редравим пассивную панель, а потом активную!
				AnotherPanel->Redraw();
				ActivePanel->Redraw();
			}

			Global->WindowManager->EnterMainLoop();
		}

		TreeList::FlushCache();

		// очистим за собой!
		SetScreen(0,0,ScrX,ScrY,L' ',colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN));
		console.SetTextAttributes(InitAttributes);
		Global->ScrBuf->ResetLockCount();
		Global->ScrBuf->Flush();

		return 0;
}
Пример #6
0
		void UIButton::parseXMLNode( pugi::xml_node& node )
		{
			pugi::xml_node ButtonNode = node.first_child();
			ATTACH_TYPE attachTo = ATTACH_TYPE_TOPLEFT;
			ATTACH_TYPE attachFrom = ATTACH_TYPE_TOPLEFT;
			

			Vector2f offset = Vector2f(0.f, 0.f);
			Vector2f size = Vector2f(.1f, .1f);

			while(ButtonNode)
			{
				std::string name(ButtonNode.name());

				//TODO
				//
				if(_stricmp(name.c_str(), "Texture") == 0)
				{
					m_textureName = ButtonNode.attribute("file").as_string();
				}
				else if(_stricmp(name.c_str(), "LinkWindow") == 0)
				{
					std::string windowName = ButtonNode.attribute("name").as_string();
					EventToCall event, event2;
					event.eventName = "ShowWindow";
					event.parameters.insertNamedData("WindowName", windowName);
					m_eventsToCallWhenPushed.push_back(event);
					event2.eventName = "HideWindow";
					event2.parameters.insertNamedData("WindowName", windowName);
					m_eventsToCallWhenReleased.push_back(event2);
				}
				else if(_stricmp(name.c_str(), "Event") == 0)
				{
					EventToCall event;
					event.eventName = ButtonNode.attribute("event").as_string();

					pugi::xml_node eventNode = ButtonNode.first_child();

					while (eventNode)
					{
						std::string ename(eventNode.name());
						if(_stricmp(ename.c_str(), "ParamString") == 0)
						{
							event.parameters.insertNamedData(eventNode.attribute("name").as_string(), std::string(eventNode.attribute("value").as_string() ) );
						}
						eventNode = eventNode.next_sibling();
					}

					std::string call = ButtonNode.attribute("call").as_string();
					if(_stricmp(call.c_str(), "Push") == 0 )
					{
						m_eventsToCallWhenPushed.push_back(event);
					}
					else if(_stricmp(call.c_str(), "Release") == 0 )
					{
						m_eventsToCallWhenReleased.push_back(event);
					}
				}

				ButtonNode = ButtonNode.next_sibling();
			}

			m_containedBox.setMinAttachType(attachFrom);
			m_containedBox.setMaxAttachType(attachFrom);

			
		}
Пример #7
0
void XmlWriter::tag(const QString& name, QVariant data)
      {
      QString ename(name.split(' ')[0]);

      putLevel();
      switch(data.type()) {
            case QVariant::Bool:
            case QVariant::Char:
            case QVariant::Int:
            case QVariant::UInt:
                  *this << "<" << name << ">";
                  *this << data.toInt();
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::Double:
                  *this << "<" << name << ">";
                  *this << data.value<double>();
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::String:
                  *this << "<" << name << ">";
                  *this << xmlString(data.value<QString>());
                  *this << "</" << ename << ">\n";
                  break;
            case QVariant::Color:
                  {
                  QColor color(data.value<QColor>());
                  *this << QString("<%1 r=\"%2\" g=\"%3\" b=\"%4\" a=\"%5\"/>\n")
                     .arg(name).arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha());
                  }
                  break;
            case QVariant::Rect:
                  {
                  const QRect& r(data.value<QRect>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\" w=\"%4\" h=\"%5\"/>\n").arg(name).arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
                  }
                  break;
            case QVariant::RectF:
                  {
                  const QRectF& r(data.value<QRectF>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\" w=\"%4\" h=\"%5\"/>\n").arg(name).arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
                  }
                  break;
            case QVariant::PointF:
                  {
                  const QPointF& p(data.value<QPointF>());
                  *this << QString("<%1 x=\"%2\" y=\"%3\"/>\n").arg(name).arg(p.x()).arg(p.y());
                  }
                  break;
            case QVariant::SizeF:
                  {
                  const QSizeF& p(data.value<QSizeF>());
                  *this << QString("<%1 w=\"%2\" h=\"%3\"/>\n").arg(name).arg(p.width()).arg(p.height());
                  }
                  break;
            default: {
                  const char* type = data.typeName();
                  if (strcmp(type, "Ms::Spatium") == 0) {
                        *this << "<" << name << ">";
                        *this << data.value<Spatium>().val();
                        *this << "</" << ename << ">\n";
                        }
                  else if (strcmp(type, "Ms::Fraction") == 0) {
                        const Fraction& f = data.value<Fraction>();
                        *this << QString("<%1>%2/%3</%1>\n").arg(name).arg(f.numerator()).arg(f.denominator());
                        }
                  else if (strcmp(type, "Ms::Direction") == 0)
                        *this << QString("<%1>%2</%1>\n").arg(name).arg(data.value<Direction>().toString());
                  else if (strcmp(type, "Ms::Align") == 0) {
                        Align a = Align(data.toInt());
                        const char* h;
                        if (a & Align::HCENTER)
                              h = "center";
                        else if (a & Align::RIGHT)
                              h = "right";
                        else
                              h = "left";
                        const char* v;
                        if (a & Align::BOTTOM)
                              v = "bottom";
                        else if (a & Align::VCENTER)
                              v = "center";
                        else if (a & Align::BASELINE)
                              v = "baseline";
                        else
                              v = "top";
                        *this << QString("<%1>%2,%3</%1>\n").arg(name).arg(h).arg(v);
                        }
                  else {
                        qFatal("XmlWriter::tag: unsupported type %d %s", data.type(), type);
                        }
                  }
                  break;
            }
      }