示例#1
0
 /// Create a new URLSearchPath.
 /// \param[in] t_path local path to search
 /// \param[in] t_relativity If t_url is a relative path, it is evaluated relative to t_relativity.
 URLSearchPath(const openstudio::path &t_path, Relative t_relativity = ToInputFile)
     : m_url(QUrl::fromLocalFile(toQString(t_path))), m_relativity(t_relativity)
 {
 }
示例#2
0
/** UTF-8 encoded std::string to path*/
path toPath(const std::string& s) 
{
  return toPath(toQString(s));
}
示例#3
0
  QVariant toVariant(const OSArgument& argument) {
    QVariantMap argumentData;

    argumentData["uuid"] = toQString(removeBraces(argument.uuid()));
    argumentData["version_uuid"] = toQString(removeBraces(argument.versionUUID()));
    argumentData["name"] = toQString(argument.name());
    if (!argument.displayName().empty()) {
      argumentData["display_name"] = toQString(argument.displayName());
    }
    if (argument.description() && !argument.description()->empty()) {
      argumentData["description"] = toQString(argument.description().get());
    }
    OSArgumentType type = argument.type();
    if (argument.units() && !argument.units()->empty()) {
      argumentData["units"] = toQString(argument.units().get());
    }
    argumentData["type"] = toQString(type.valueName());
    argumentData["required"] = argument.required();
    argumentData["model_dependent"] = argument.modelDependent();
    if (argument.hasValue()) {
      if (type == OSArgumentType::Quantity) {
        Quantity value = argument.valueAsQuantity();
        argumentData["value"] = value.value();
        argumentData["value_units"] = toQString(value.units().standardString());
      }
      else {
        // use QVariant directly
        argumentData["value"] = argument.valueAsQVariant();
      }
    }
    if (argument.hasDefaultValue()) {
      if (type == OSArgumentType::Quantity) {
        Quantity defaultValue = argument.defaultValueAsQuantity();
        argumentData["default_value"] = defaultValue.value();
        argumentData["default_value_units"] = toQString(defaultValue.units().standardString());
      }
      else {
        // use QVariant directly
        argumentData["default_value"] = argument.defaultValueAsQVariant();
      }
    }
    argumentData["domain_type"] = toQString(argument.domainType().valueName());
    if (argument.hasDomain()) {
      QVariantList domainList;
      int index(0);
      for (const QVariant& dval : argument.domainAsQVariant()) {
        QVariantMap domainValueMap;
        domainValueMap["domain_value_index"] = index;
        if (type == OSArgumentType::Quantity) {
          Quantity q = dval.value<openstudio::Quantity>();
          domainValueMap["value"] = q.value();
          domainValueMap["units"] = toQString(q.units().standardString());
        }
        else {
          domainValueMap["value"] = dval;
        }
        domainList.push_back(domainValueMap);
        ++index;
      }
      argumentData["domain"] = domainList;
    }
    if (type == OSArgumentType::Choice) {
      QVariantList choicesList;
      StringVector displayNames = argument.choiceValueDisplayNames();
      int index(0), displayNamesN(displayNames.size());
      for (const std::string& choice : argument.choiceValues()) {
        QVariantMap choiceMap;
        choiceMap["choice_index"] = index;
        choiceMap["value"] = toQString(choice);
        if (index < displayNamesN) {
          choiceMap["display_name"] = toQString(displayNames[index]);
        }
        choicesList.push_back(choiceMap);
        ++index;
      }
      argumentData["choices"] = QVariant(choicesList);
    }
    if (type == OSArgumentType::Path) {
      argumentData["is_read"] = argument.isRead();
      argumentData["extension"] = toQString(argument.extension());
    }

    return QVariant(argumentData);
  }
示例#4
0
QEvent::Type JSEventMapper::findEventType( const KJS::Identifier &name ) const
{
    return  m_handlerToEvent[ toQString(name) ];
}
  void OutputAttributeVariableRecord_Impl::bindValues(QSqlQuery& query) const {
    OutputVariableRecord_Impl::bindValues(query);

    query.bindValue(OutputAttributeVariableRecord::ColumnsType::attributeName,
                    toQString(m_attributeName));
  }
/*
 * ProcessSnapshotModel::Item::Item
 */
ProcessSnapshotModel::Item::Item(PROCESSENTRY32& pe, Item *parent) 
        : child(NULL), exe(toQString(pe.szExeFile)), parent(parent), 
        isAttachable(false), pid(pe.th32ProcessID) {
    HANDLE hProcess = NULL;     // Process handle.
    HANDLE hToken = NULL;       // Process security token.
    HANDLE hSnapshot = NULL;    // Snapshot of process modules.
    MODULEENTRY32 me;           // For iterating modules.

    if ((hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, 
            this->pid)) != NULL) {
        // TODO: System UNC path is too weird.
        //char tmp[MAX_PATH];
        //if (::GetProcessImageFileNameA(hProcess, tmp, MAX_PATH)) {
        //    this->exe = QString(tmp);
        //}
    
        if (::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) {
            
            /* User user information about process token. */
            DWORD userInfoLen = 0;
            if (::GetTokenInformation(hToken, TokenUser, NULL, 0, &userInfoLen) 
                    || (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
                char *userInfo = new char[userInfoLen];
            
                if (::GetTokenInformation(hToken, TokenUser, userInfo, 
                        userInfoLen, &userInfoLen)) {
                    PSID sid = reinterpret_cast<TOKEN_USER *>(
                        userInfo)->User.Sid;
                
                    /* Lookup the user name of the SID. */
                    DWORD userNameLen = 0;
                    DWORD domainLen = 0;
                    SID_NAME_USE snu = SidTypeUnknown;
                    if (::LookupAccountSidA(NULL, sid, NULL, &userNameLen, 
                            NULL, &domainLen, &snu) || (::GetLastError() 
                            == ERROR_INSUFFICIENT_BUFFER)) {
                        char *userName = new char[userNameLen];
                        char *domain = new char[domainLen];
                        if (::LookupAccountSidA(NULL, sid, userName, 
                                &userNameLen, domain, &domainLen, &snu)) {
                            this->owner = QString(domain) + "\\" 
                                + QString(userName);
                            this->isAttachable = true;
                            // Note: If we cannot get the owner SID, the owner
                            // is probably SYSTEM and we cannot attach to
                            // system processes.
                        }
                        delete[] userName;
                        delete[] domain;
                    }
                }
    
                delete[] userInfo;
            }
            ::CloseHandle(hToken);
        }

        ::CloseHandle(hProcess);
    }

    /* Check whether the process has OpenGL loaded. */
    if (this->isAttachable) {
        this->isAttachable = false;

        // Note: If we cannot enumerate the modules, we probably cannot attach,
        // too, because of insufficient privileges.
        if ((hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 
                this->pid)) != INVALID_HANDLE_VALUE) {
            me.dwSize = sizeof(me);

            if (::Module32First(hSnapshot, &me)) {
                do {
                    QString name = toQString(me.szModule);
                    if (name.contains("opengl", Qt::CaseInsensitive)) {
                        this->isAttachable = true;
                        break;
                    }
                } while (::Module32Next(hSnapshot, &me));
            }
        }

        ::CloseHandle(hSnapshot);
    }

    /* Attaching to the debugger is forbidden, too. */
    if (this->pid == ::GetCurrentProcessId()) {
        this->isAttachable = false;
    }

    // TODO: Should it be forbidden to attach to process that have the
    // debug library already loaded?
}
 QString ForwardTranslator::escapeName(const std::string& name)
 {
   return toQString(name);
 }
  boost::optional<QDomDocument> ForwardTranslator::translateModel(const openstudio::model::Model& model)
  {
    QDomDocument doc;
    doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");

    QDomElement sddElement = doc.createElement("SDDXML");
    sddElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    sddElement.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
    doc.appendChild(sddElement);

    // set ruleset, where should this data come from?
    QDomElement rulesetFilenameElement = doc.createElement("RulesetFilename");
    sddElement.appendChild(rulesetFilenameElement);
    rulesetFilenameElement.setAttribute("file", "CEC 2013 NonRes.bin"); // DLM: only allow one value for now

    // set project, where should this data come from?
    QDomElement projectElement = doc.createElement("Proj");
    sddElement.appendChild(projectElement);

    // DLM: what name to use here?
    QDomElement projectNameElement = doc.createElement("Name");
    projectElement.appendChild(projectNameElement);
    projectNameElement.appendChild(doc.createTextNode("unknown"));

    // site data
    boost::optional<model::ClimateZones> climateZones = model.getOptionalUniqueModelObject<model::ClimateZones>();
    if (climateZones){
      // todo: check document year
      std::vector<model::ClimateZone> zones = climateZones->getClimateZones("CEC");
      if (zones.size() > 0 && !zones[0].value().empty()){

        bool isNumber;
        QString value = toQString(zones[0].value());
        value.toInt(&isNumber);
        if (isNumber){
          value = QString("ClimateZone") + value;
        }

        QDomElement projectClimateZoneElement = doc.createElement("CliZn");
        projectElement.appendChild(projectClimateZoneElement);
        projectClimateZoneElement.appendChild(doc.createTextNode(value));

        m_translatedObjects[climateZones->handle()] = projectClimateZoneElement;
      }
    }

    // set lat, lon, elev
    // DLM: do not translate forward,  Issue 242: Forward Translator - Remove Proj:Lat/Lon/Elevation translation
    /*
    boost::optional<model::Site> site = model.getOptionalUniqueModelObject<model::Site>();
    if (site){
      double latitude = site->latitude();
      QDomElement latElement = doc.createElement("Lat");
      projectElement.appendChild(latElement);
      latElement.appendChild( doc.createTextNode(QString::number(latitude)));

      double longitude = site->longitude();
      QDomElement longElement = doc.createElement("Long");
      projectElement.appendChild(longElement);
      longElement.appendChild( doc.createTextNode(QString::number(longitude)));

      double elevationSI = site->elevation();
      double elevationIP = elevationSI/0.3048;
      QDomElement elevationElement = doc.createElement("Elevation");
      projectElement.appendChild(elevationElement);
      elevationElement.appendChild( doc.createTextNode(QString::number(elevationIP)));

      m_translatedObjects[site.handle()] = latElement;
    }
    */

    // todo: write out epw file path
    // todo: write out ddy file and set path
    //<DDWeatherFile>C:/svn-CBECC-Com-130521/CBECC-Com13/Data/EPW/SACRAMENTO-EXECUTIVE_724830_CZ2010.ddy</DDWeatherFile>
    //<AnnualWeatherFile>C:/svn-CBECC-Com-130521/CBECC-Com13/Data/EPW/SACRAMENTO-EXECUTIVE_724830_CZ2010.epw</AnnualWeatherFile>
    //<HVACAutoSizing>1</HVACAutoSizing>
    //<SimDsgnDays>1</SimDsgnDays>
    //<RunPeriodBeginMonth>0</RunPeriodBeginMonth>
    //<RunPeriodBeginDay>0</RunPeriodBeginDay>
    //<RunPeriodEndMonth>0</RunPeriodEndMonth>
    //<RunPeriodEndDay>0</RunPeriodEndDay>
    //<RunPeriodYear>0</RunPeriodYear>

    // do materials before constructions 
    std::vector<model::Material> materials = model.getModelObjects<model::Material>();
    std::sort(materials.begin(), materials.end(), WorkspaceObjectNameLess());

    if (m_progressBar){
      m_progressBar->setWindowTitle(toString("Translating Materials"));
      m_progressBar->setMinimum(0);
      m_progressBar->setMaximum((int)materials.size());
      m_progressBar->setValue(0);
    }

    for (const model::Material& material : materials){

      boost::optional<QDomElement> materialElement = translateMaterial(material, doc);
      if (materialElement){
        projectElement.appendChild(*materialElement);
      }

      if (m_progressBar){
        m_progressBar->setValue(m_progressBar->value() + 1);
      }
    }
  
    // do constructions before geometry

    std::vector<model::ConstructionBase> constructions = model.getModelObjects<model::ConstructionBase>();
    std::sort(constructions.begin(), constructions.end(), WorkspaceObjectNameLess());

    if (m_progressBar){
      m_progressBar->setWindowTitle(toString("Translating Constructions"));
      m_progressBar->setMinimum(0);
      m_progressBar->setMaximum(3 * ((int)constructions.size())); // three loops below
      m_progressBar->setValue(0);
    }

    std::set<Handle> surfaceConstructions;
    for (const model::Surface& surface : model.getConcreteModelObjects<model::Surface>()){
      boost::optional<model::ConstructionBase> construction = surface.construction();
      if (construction){
        surfaceConstructions.insert(construction->handle());
      }
    }

    std::set<Handle> doorConstructions;
    std::set<Handle> fenestrationConstructions;
    for (const model::SubSurface& subSurface : model.getConcreteModelObjects<model::SubSurface>()){
      boost::optional<model::ConstructionBase> construction = subSurface.construction();
      if (construction){
        std::string subSurfaceType = subSurface.subSurfaceType();
        if (istringEqual("Door", subSurfaceType) || istringEqual("OverheadDoor", subSurfaceType)){
          doorConstructions.insert(construction->handle());
        }else{
          fenestrationConstructions.insert(construction->handle());
        }
      }
    }

    // translate surface constructions
    for (const model::ConstructionBase& constructionBase : constructions){
      if (surfaceConstructions.find(constructionBase.handle()) == surfaceConstructions.end()){
        continue;
      }

      boost::optional<QDomElement> constructionElement = translateConstructionBase(constructionBase, doc);
      if (constructionElement){
        projectElement.appendChild(*constructionElement);
      }
            
      if (m_progressBar){
        m_progressBar->setValue(m_progressBar->value() + 1);
      }
    }

    // translate door constructions
    for (const model::ConstructionBase& constructionBase : constructions){
      if (doorConstructions.find(constructionBase.handle()) == doorConstructions.end()){
        continue;
      }

      boost::optional<QDomElement> constructionElement = translateDoorConstruction(constructionBase, doc);
      if (constructionElement){
        projectElement.appendChild(*constructionElement);
      }
            
      if (m_progressBar){
        m_progressBar->setValue(m_progressBar->value() + 1);
      }
    }

    // translate fenestration constructions
    for (const model::ConstructionBase& constructionBase : constructions){
      if (fenestrationConstructions.find(constructionBase.handle()) == fenestrationConstructions.end()){
        continue;
      }

      boost::optional<QDomElement> constructionElement = translateFenestrationConstruction(constructionBase, doc);
      if (constructionElement){
        projectElement.appendChild(*constructionElement);
      }

      if (m_progressBar){
        m_progressBar->setValue(m_progressBar->value() + 1);
      }
    }

    // translate site shading
    std::vector<model::ShadingSurfaceGroup> shadingSurfaceGroups = model.getConcreteModelObjects<model::ShadingSurfaceGroup>();
    std::sort(shadingSurfaceGroups.begin(), shadingSurfaceGroups.end(), WorkspaceObjectNameLess());

    if (m_progressBar){
      m_progressBar->setWindowTitle(toString("Translating Site Shading"));
      m_progressBar->setMinimum(0);
      m_progressBar->setMaximum((int)shadingSurfaceGroups.size()); 
      m_progressBar->setValue(0);
    }

    for (const model::ShadingSurfaceGroup& shadingSurfaceGroup : shadingSurfaceGroups){
      if (istringEqual(shadingSurfaceGroup.shadingSurfaceType(), "Site")){

        Transformation transformation = shadingSurfaceGroup.siteTransformation();

        for (const model::ShadingSurface& shadingSurface : shadingSurfaceGroup.shadingSurfaces()){
          boost::optional<QDomElement> shadingSurfaceElement = translateShadingSurface(shadingSurface, transformation, doc);
          if (shadingSurfaceElement){
            projectElement.appendChild(*shadingSurfaceElement);
          }
        }
      }

      if (m_progressBar){
        m_progressBar->setValue(m_progressBar->value() + 1);
      }
    }

    // translate the building
    boost::optional<model::Building> building = model.getOptionalUniqueModelObject<model::Building>();
    if (building){
      boost::optional<QDomElement> buildingElement = translateBuilding(*building, doc);
      if (buildingElement){
        projectElement.appendChild(*buildingElement);
      }
    }

    m_ignoreTypes.push_back(model::BoilerSteam::iddObjectType());
    m_ignoreTypes.push_back(model::ClimateZones::iddObjectType()); // might not be translated but it is checked
    m_ignoreTypes.push_back(model::CoilCoolingDXMultiSpeedStageData::iddObjectType());
    m_ignoreTypes.push_back(model::CoilHeatingGasMultiStageStageData::iddObjectType());
    m_ignoreTypes.push_back(model::ComponentCostAdjustments::iddObjectType());
    m_ignoreTypes.push_back(model::ComponentData::iddObjectType());
    m_ignoreTypes.push_back(model::Connection::iddObjectType());
    m_ignoreTypes.push_back(model::ControllerWaterCoil::iddObjectType());
    m_ignoreTypes.push_back(model::ConvergenceLimits::iddObjectType());
    m_ignoreTypes.push_back(model::CoolingTowerPerformanceCoolTools::iddObjectType());
    m_ignoreTypes.push_back(model::CoolingTowerPerformanceYorkCalc::iddObjectType());
    m_ignoreTypes.push_back(model::CurrencyType::iddObjectType());
    m_ignoreTypes.push_back(model::CurveBicubic::iddObjectType());
    m_ignoreTypes.push_back(model::CurveBiquadratic::iddObjectType());
    m_ignoreTypes.push_back(model::CurveCubic::iddObjectType());
    m_ignoreTypes.push_back(model::CurveDoubleExponentialDecay::iddObjectType());
    m_ignoreTypes.push_back(model::CurveExponent::iddObjectType());
    m_ignoreTypes.push_back(model::CurveExponentialDecay::iddObjectType());
    m_ignoreTypes.push_back(model::CurveExponentialSkewNormal::iddObjectType());
    m_ignoreTypes.push_back(model::CurveFanPressureRise::iddObjectType());
    m_ignoreTypes.push_back(model::CurveFunctionalPressureDrop::iddObjectType());
    m_ignoreTypes.push_back(model::CurveLinear::iddObjectType());
    m_ignoreTypes.push_back(model::CurveQuadratic::iddObjectType());
    m_ignoreTypes.push_back(model::CurveQuadraticLinear::iddObjectType());
    m_ignoreTypes.push_back(model::CurveQuartic::iddObjectType());
    m_ignoreTypes.push_back(model::CurveRectangularHyperbola1::iddObjectType());
    m_ignoreTypes.push_back(model::CurveRectangularHyperbola2::iddObjectType());
    m_ignoreTypes.push_back(model::CurveSigmoid::iddObjectType());
    m_ignoreTypes.push_back(model::CurveTriquadratic::iddObjectType());
    m_ignoreTypes.push_back(model::DefaultConstructionSet::iddObjectType());
    m_ignoreTypes.push_back(model::DesignDay::iddObjectType());
    m_ignoreTypes.push_back(model::DefaultScheduleSet::iddObjectType());
    m_ignoreTypes.push_back(model::DesignSpecificationZoneAirDistribution::iddObjectType());
    m_ignoreTypes.push_back(model::DefaultSurfaceConstructions::iddObjectType());
    m_ignoreTypes.push_back(model::DefaultSubSurfaceConstructions::iddObjectType());
    m_ignoreTypes.push_back(model::Facility::iddObjectType());
    m_ignoreTypes.push_back(model::HeatBalanceAlgorithm::iddObjectType());
    m_ignoreTypes.push_back(model::IlluminanceMap::iddObjectType());
    m_ignoreTypes.push_back(model::InsideSurfaceConvectionAlgorithm::iddObjectType());
    m_ignoreTypes.push_back(model::InternalMass::iddObjectType());
    m_ignoreTypes.push_back(model::LifeCycleCost::iddObjectType());
    m_ignoreTypes.push_back(model::LifeCycleCostParameters::iddObjectType());
    m_ignoreTypes.push_back(model::LightingDesignDay::iddObjectType());
    m_ignoreTypes.push_back(model::LightingSimulationControl::iddObjectType());
    m_ignoreTypes.push_back(model::Meter::iddObjectType());
    m_ignoreTypes.push_back(model::ModelObjectList::iddObjectType());
    m_ignoreTypes.push_back(model::Node::iddObjectType());
    m_ignoreTypes.push_back(model::OutputControlReportingTolerances::iddObjectType());
    m_ignoreTypes.push_back(model::OutputVariable::iddObjectType());
    m_ignoreTypes.push_back(model::OutsideSurfaceConvectionAlgorithm::iddObjectType());
    m_ignoreTypes.push_back(model::PortList::iddObjectType());
    m_ignoreTypes.push_back(model::ProgramControl::iddObjectType());
    m_ignoreTypes.push_back(model::RadianceParameters::iddObjectType());
    m_ignoreTypes.push_back(model::RenderingColor::iddObjectType());
    m_ignoreTypes.push_back(model::RunPeriod::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleCompact::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleConstant::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleDay::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleFixedInterval::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleRule::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleRuleset::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleTypeLimits::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleVariableInterval::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleWeek::iddObjectType());
    m_ignoreTypes.push_back(model::ScheduleYear::iddObjectType());
    m_ignoreTypes.push_back(model::SetpointManagerMixedAir::iddObjectType());
    m_ignoreTypes.push_back(model::ShadowCalculation::iddObjectType());
    m_ignoreTypes.push_back(model::SimulationControl::iddObjectType());
    m_ignoreTypes.push_back(model::Site::iddObjectType()); // might not be translated but it is checked
    m_ignoreTypes.push_back(model::SiteGroundReflectance::iddObjectType());
    m_ignoreTypes.push_back(model::SiteGroundTemperatureBuildingSurface::iddObjectType());
    m_ignoreTypes.push_back(model::SiteWaterMainsTemperature::iddObjectType());
    m_ignoreTypes.push_back(model::SizingParameters::iddObjectType());
    m_ignoreTypes.push_back(model::SkyTemperature::iddObjectType());
    m_ignoreTypes.push_back(model::StandardsInformationConstruction::iddObjectType());
    m_ignoreTypes.push_back(model::StandardsInformationMaterial::iddObjectType());
    m_ignoreTypes.push_back(model::TableMultiVariableLookup::iddObjectType());
    m_ignoreTypes.push_back(model::Timestep::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityBill::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Charge_Block::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Charge_Simple::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Computation::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Qualify::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Ratchet::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Tariff::iddObjectType());
    m_ignoreTypes.push_back(model::UtilityCost_Variable::iddObjectType());
    m_ignoreTypes.push_back(model::Version::iddObjectType());
    m_ignoreTypes.push_back(model::WeatherFile::iddObjectType());
    m_ignoreTypes.push_back(model::WeatherFileConditionType::iddObjectType());
    m_ignoreTypes.push_back(model::WeatherFileDays::iddObjectType());
    m_ignoreTypes.push_back(model::YearDescription::iddObjectType());
    m_ignoreTypes.push_back(model::ZoneAirContaminantBalance::iddObjectType());
    m_ignoreTypes.push_back(model::ZoneAirHeatBalanceAlgorithm::iddObjectType());
    m_ignoreTypes.push_back(model::ZoneCapacitanceMultiplierResearchSpecial::iddObjectType());
    m_ignoreTypes.push_back(model::ZoneHVACEquipmentList::iddObjectType());

    return doc;
  }
示例#9
0
QUrl toURL(const openstudio::path& p) {
  return QUrl::fromLocalFile(toQString(p));
}
示例#10
0
void OSIntegerEdit2::refreshTextAndLabel() {

  QString text = this->text();

  if (m_text == text) return;

  if (m_modelObject) {
    QString textValue;
    ModelObject modelObject = m_modelObject.get();
    std::stringstream ss;

    if (m_isAutosized && (*m_isAutosized)()) {
      textValue = QString("autosize");
    }

    if (m_isAutocalculated && (*m_isAutocalculated)()) {
      textValue = QString("autocalculate");
    }

    OptionalInt oi;
    if (m_get) {
      oi = (*m_get)();
    }
    else {
      OS_ASSERT(m_getOptional);
      oi = (*m_getOptional)();
    }
    if (oi) {
      int value = *oi;
      if (m_isScientific) {
        ss << std::scientific;
      }
      else {
        ss << std::fixed;
      }
      if (m_precision) {
        ss << std::setprecision(*m_precision);
      }
      ss << value;
      textValue = toQString(ss.str());
      ss.str("");
    }

    if (!textValue.isEmpty() && m_text != textValue){
      m_text = textValue;
      this->blockSignals(true);
      this->setText(m_text);
      this->blockSignals(false);
    }
    else {
      return;
    }

    if (m_isDefaulted) {
      if ((*m_isDefaulted)()) {
        this->setStyleSheet("color:green");
      }
      else {
        this->setStyleSheet("color:black");
      }
    }
  }
}
示例#11
0
void OrganizerItemGuidTransform::transformToDetailL(const CCalEntry& entry, QOrganizerItem *item)
{
    QString guid = toQString(entry.UidL());
    if (!guid.isEmpty())
        item->setGuid(guid);
}
示例#12
0
/// get the QApplication, if no QApplication has been set this will create a default one
QCoreApplication* ApplicationSingleton::application(bool gui)
{
  if (!m_qApplication){

    if (QCoreApplication::instance())
    {

      m_qApplication = QCoreApplication::instance();

    } else {

      QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
      QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);

      // Add this path for gem case (possibly deprecated)
      QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory() / toPath("plugins")));

      // And for any other random cases (possibly deprecated, applies to super-built Qt on Linux)
      QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory().parent_path() / toPath("share/openstudio-" + openStudioVersion() + "/qtplugins")));

      // Make the run path the backup plugin search location
      QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory()));

      // Make the ruby path the default plugin search location
#if defined(Q_OS_MAC)
      openstudio::path p = getApplicationRunDirectory().parent_path().parent_path().parent_path() / toPath("Ruby/openstudio");
      QCoreApplication::addLibraryPath(toQString(p));
#elif defined(Q_OS_WIN)
      openstudio::path p = getApplicationRunDirectory().parent_path() / toPath("Ruby/openstudio");
      QCoreApplication::addLibraryPath(toQString(p));
#endif

      static char *argv[] = {nullptr};
      static int argc = sizeof(argv) / sizeof(char*) - 1;

      // Load the qpa plugin (If SketchUp is loading the OpenStudio plugin, the SketchUp run path will be added to the end of libraryPaths)
      if (gui){
        m_qApplication = new QApplication(argc, argv);
        dynamic_cast<QApplication*>(m_qApplication)->setQuitOnLastWindowClosed(false);
      }else{
        m_qApplication = new QCoreApplication(argc, argv);
      }

      
      m_defaultInstance = true;

      // check if we are in a SketchUp process
      #if _WIN32 || _MSC_VER
        if (gui){
          DWORD pId = GetCurrentProcessId();
          //HMODULE hModule = GetModuleHandle(NULL); // same as hInstance
          LPTSTR className = new TCHAR[255];
          LPTSTR typeName = new TCHAR[255];
          HWND h = GetTopWindow(0);
          while (h)
          {
            DWORD pId2;
            GetWindowThreadProcessId(h, &pId2);

            if (pId == pId2){

              GetClassName(h, className, 255);
              GetWindowText(h, typeName, 255);

              if (boost::regex_match(toString(typeName), boost::regex(".*- SketchUp.*"))){
                m_sketchUpWidget = new QWinWidget(h);
                break;
              }
            }

            h = GetNextWindow(h, GW_HWNDNEXT);
          }

          delete[] className;
          delete[] typeName;
        }
      #endif

    }
  }

  return m_qApplication;
}
void ExternalObjectInterface::addPropertyName(const std::string& name)
{
  m_propertyNames.push_back(toQString(name));
}
示例#14
0
 /// Create a new URLSearchPath.
 /// \param[in] t_path local path to search
 /// \param[in] t_relativity If t_url is a relative path, it is evaluated relative to t_relativity.
 /// \param[in] t_object_type Object type to apply this search to
 URLSearchPath(const openstudio::path &t_path, Relative t_relativity, IddObjectType t_object_type)
     : m_url(QUrl::fromLocalFile(toQString(t_path))), m_relativity(t_relativity), m_object_type(t_object_type)
 {
 }
void MeasuresTabController::selectBaseline()
{
  boost::optional<analysisdriver::SimpleProject> project = PatApp::instance()->project();
  if (!project){
    return;
  }

  if (project->isRunning()){
    // warn user that they will have to stop running to change baseline model
    QMessageBox::StandardButton test = QMessageBox::question( measuresTabView, "Stop Current Analysis?", "You must stop the currently running analysis before changing the baseline model, do you want to proceed?", QMessageBox::Yes |  QMessageBox::No, QMessageBox::No );
    if (test == QMessageBox::No){
      return;
    }

    project->stop();
  }

  if (project->analysis().completeDataPoints().size() > 0u){
    // warn user that this will blow away their data points
    QMessageBox::StandardButton test = QMessageBox::question( 
        measuresTabView, 
        "Change Baseline Model?", 
        "Changing your baseline model will remove all results and save your project, do you want to proceed?", 
        QMessageBox::Yes |  QMessageBox::No, 
        QMessageBox::No );
    if (test == QMessageBox::No){
      return;
    }
  }

  // DLM: todo, allow user to clear baseline?

  QString fileName = QFileDialog::getOpenFileName( measuresTabView,
                                                   tr("Select Baseline Model"),
                                                   QDir::homePath(),
                                                   tr("(*.osm)") );

  if (!fileName.isEmpty()){
    QDir projectDir(toQString(project->projectDir()));
    if (projectDir.relativeFilePath(fileName).startsWith("seed")){
      QMessageBox::warning( measuresTabView, "Changing Baseline Model Failed", QString("The new baseline model cannot be located within the project's seed directory."));
      return;
    }
    FileReference seed(toPath(fileName));
    // DLM: make sure to call setSeed on the real project, not a copy
    if (PatApp::instance()->setSeed(seed)){

      if (seed.displayName().empty() || seed.displayName() == "*"){
        measuresTabView->baselineCautionLabel->setHidden(false);
        measuresTabView->baselineNameBackground->setHidden(true);
        measuresTabView->baselineLabel->setText(QString());
      }else{
        measuresTabView->baselineCautionLabel->setHidden(true);
        measuresTabView->baselineNameBackground->setHidden(false);
        measuresTabView->baselineLabel->setText(toQString(seed.displayName()));
      }

      // change cannot be undone, save the project
      PatApp::instance()->project()->save();

      //QMessageBox::information( measuresTabView, "Baseline Model Changed", QString("Baseline model has been changed, please run a baseline simulation with this new baseline model before continuing on with new work.") );

      m_variableGroupListController->selectionController()->unselectAllItems();

    }else{
      // tell user that this failed
      QMessageBox::critical( measuresTabView, "Changing Baseline Model Failed", QString("Failed to change baseline model to file at '") + fileName + QString("'."));
    }
  }
}
示例#16
0
QUrl toURL(const std::string& s) {
  return QUrl(toQString(s));
}
bool QSanProtocol::Utils::tryParse(const Json::Value &arg, QString &result) {
    if (!arg.isString()) return false;
    result = toQString(arg);
    return true;
}
示例#18
0
OSItemId modelObjectToItemId(const openstudio::model::ModelObject& modelObject, bool isDefaulted)
{
  std::stringstream ss;
  ss << modelObject;
  return OSItemId(modelObject.handle().toString(), modelToSourceId(modelObject.model()), isDefaulted, toQString(ss.str()));
}
 std::string BCLFileReference::fileType() const
 {
   return toString(toQString(m_path.extension()).replace(".", ""));
 }
示例#20
0
/** wstring to std::string. */
std::string toString(const std::wstring& w)
{
  return toString(toQString(w));
}
示例#21
0
void JSEventMapper::addEvent( const KJS::Identifier &name, QEvent::Type t )
{
    m_handlerToEvent[ toQString(name) ] = t;
    m_eventToHandler[ t ] = name;
}
示例#22
0
 FileInfo RunManager_Util::dirFile(const openstudio::path &p)
 {
   return dirFile(QFileInfo(toQString(p)));
 }
示例#23
0
bool JSEventMapper::isEventHandler( const KJS::Identifier &name ) const
{
    return m_handlerToEvent.contains( toQString(name) );
}
示例#24
0
QString CleanupTab::pathString(const TFilePath &path, bool lpNone)
{
	return path.isEmpty() ? lpNone ? QString("+extras") : QString("+drawings") : toQString(path);
}
示例#25
0
/** path to QString. */
QString toQString(const path& p) 
{
  return toQString(p.string());
}
void RenderCommand::flashRender()
{
	ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
	TSceneProperties *sprop = scene->getProperties();
	FILE *fileP = fopen(m_fp, "wb");
	if (!fileP)
		return;
	ProgressDialog pb("rendering " + toQString(m_fp), "Cancel", 0, m_numFrames);
	pb.show();

	TDimension cameraSize = scene->getCurrentCamera()->getRes();
	double frameRate = sprop->getOutputProperties()->getFrameRate();
	TFlash flash(
		cameraSize.lx,
		cameraSize.ly,
		m_numFrames,
		frameRate,
		sprop->getOutputProperties()->getFileFormatProperties("swf"));
	flash.setBackgroundColor(sprop->getBgColor());

	std::vector<TXshSoundColumn *> columns;
	scene->getSoundColumns(columns);
	if (!columns.empty()) {
		TXsheet::SoundProperties *prop = new TXsheet::SoundProperties();
		prop->m_frameRate = frameRate;
		TSoundTrack *st = scene->getXsheet()->makeSound(prop);
		if (st)
			flash.putSound(st, 0);
	}

	int i = 0;
	for (i = 0; i < m_numFrames; ++i, m_r += m_stepd) {
		flash.beginFrame(m_step * i + 1);
		TRasterFxP rfx = buildSceneFx(scene, m_r, 0, false);
		assert(rfx);
		rfx->compute(flash, tround(m_r)); // WARNING: This should accept a DOUBLE...
#ifdef BRAVODEMO
		TRasterImageP ri(loadBravo(scene->getCurrentCamera()->getRes()));
		int lx = ri->getRaster()->getLx();
		int ly = ri->getRaster()->getLx();
		flash.pushMatrix();
		int dx = tround(0.1 * (cameraSize.lx - lx));
		int dy = tround(0.1 * (cameraSize.ly - ly));
		flash.multMatrix(TTranslation((cameraSize.lx - lx) / 2 - (dx > 0 ? dx : 0), -(cameraSize.ly - ly) / 2 + (dy > 0 ? dy : 0)));
		flash.draw(ri, 0);
		flash.popMatrix();
#endif
		flash.endFrame(i == m_numFrames - 1, 0, true);
		if (pb.wasCanceled())
			break;
		pb.setValue(i + 1);
	}

	flash.writeMovie(fileP);
	fclose(fileP);

	TSystem::showDocument(m_fp);
	//QDesktopServices::openUrl(QUrl(toQString(m_fp)));

	TImageCache::instance()->remove(toString(m_fp.getWideString() + L".0"));
	TNotifier::instance()->notify(TSceneNameChange());
}
示例#27
0
/** path to UTF-8 encoding. */
std::string toString(const path& p) 
{
  return toString(toQString(p));
}
示例#28
0
  // Downloaded component from component.xml
  BCLComponent::BCLComponent(const std::string& dir):
    m_directory(dir)
  {
    QDomDocument component("component.xml");
    QFile file(toQString(m_directory+"/component.xml"));
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    component.setContent(&file);
    file.close();

    QDomElement comp = component.firstChildElement("component");
    m_name = comp.firstChildElement("name").firstChild().nodeValue().replace("_", " ")
      .toStdString();
    m_uid = comp.firstChildElement("uid").firstChild().nodeValue().toStdString();
    m_versionId = comp.firstChildElement("version_id").firstChild().nodeValue().toStdString();
    m_description = comp.firstChildElement("description").firstChild().nodeValue().toStdString();
    QDomElement componentElement = comp.firstChildElement("files").firstChildElement("file");

    while (!componentElement.isNull())
    {
      if (componentElement.hasChildNodes())
      {
        m_files.push_back(componentElement.firstChildElement("filename").firstChild()
          .nodeValue().toStdString());
        m_filetypes.push_back(componentElement.firstChildElement("filetype").firstChild()
          .nodeValue().toStdString());
      }
      else
      {
        break;
      }
      componentElement = componentElement.nextSiblingElement("file");
    }
    componentElement = comp.firstChildElement("attributes").firstChildElement("attribute");
    while (!componentElement.isNull())
    {
      if (componentElement.hasChildNodes())
      {
        std::string name = componentElement.firstChildElement("name").firstChild()
          .nodeValue().toStdString();
        std::string value = componentElement.firstChildElement("value").firstChild()
          .nodeValue().toStdString();
        std::string datatype = componentElement.firstChildElement("datatype").firstChild()
          .nodeValue().toStdString();

        // Units are optional
        std::string units = componentElement.firstChildElement("units").firstChild()
          .nodeValue().toStdString();

        if (datatype == "float"){
          if (units.empty()){
            Attribute attr(name, boost::lexical_cast<double>(value));
            m_attributes.push_back(attr);
          }else{
            Attribute attr(name, boost::lexical_cast<double>(value), units);
            m_attributes.push_back(attr);
          }
        }else if (datatype == "int"){
          if (units.empty()){
            Attribute attr(name, boost::lexical_cast<int>(value));
            m_attributes.push_back(attr);
          }else{
            Attribute attr(name, boost::lexical_cast<int>(value), units);
            m_attributes.push_back(attr);
          }
        }else if (datatype == "boolean"){
          bool temp;
          if (value == "true"){
            temp = true;
          }else{
            temp = false;
          }
          if (units.empty()){
            Attribute attr(name, temp);
            m_attributes.push_back(attr);
          }else{
            Attribute attr(name, temp, units);
            m_attributes.push_back(attr);
          }
        }else{
          // Assume string
          if (units.empty()){
            Attribute attr(name, value);
            m_attributes.push_back(attr);
          }else{
            Attribute attr(name, value, units);
            m_attributes.push_back(attr);
          }
        }
      }
      else
      {
        break;
      }
      componentElement = componentElement.nextSiblingElement("attribute");
    }
  }
void ApplyMeasureNowDialog::runMeasure()
{
  runmanager::ConfigOptions co(true);

  if (co.getTools().getAllByName("ruby").tools().size() == 0) 
  {
    QMessageBox::information(this,
      "Missing Ruby",
      "Ruby could not be located.\nOpenStudio will scan for tools.",
      QMessageBox::Ok);

    co.findTools(true);
    openstudio::runmanager::RunManager rm;
    rm.setConfigOptions(co);
    rm.showConfigGui();

    rm.getConfigOptions().saveQSettings();

    emit toolsUpdated();

    if (co.getTools().getAllByName("ruby").tools().size() == 0)
    {
      QMessageBox::information(this,
        "Missing Ruby",
        "Ruby was not located by tool search.\nPlease ensure Ruby correctly installed.\nSimulation aborted.",
        QMessageBox::Ok);

      m_mainPaneStackedWidget->setCurrentIndex(m_inputPageIdx);
      m_timer->stop();
      this->okButton()->hide();
      this->backButton()->hide();

      return;
    }
  }

  m_mainPaneStackedWidget->setCurrentIndex(m_runningPageIdx);
  m_timer->start(50);
  this->okButton()->hide();
  this->backButton()->hide();
  OS_ASSERT(m_model);

  openstudio::OSAppBase * app = OSAppBase::instance();
  m_workingDir = openstudio::toPath(app->currentDocument()->modelTempDir()) / openstudio::toPath("ApplyMeasureNow");
  openstudio::path modelPath = m_workingDir / openstudio::toPath("modelClone.osm");
  openstudio::path epwPath; // DLM: todo look at how this is done in the run tab

  removeWorkingDir();
  
  // save cloned model to temp directory
  m_model->save(modelPath,true); 

  // remove? this is shown only in debug (EW)
  QString path("Measure Output Location: ");
  path.append(toQString(m_workingDir));
  m_jobPath->setText(path);

  analysis::RubyMeasure rubyMeasure = m_currentMeasureItem->measure();

  // DLM: should be able to assert this
  bool hasIncompleteArguments = m_currentMeasureItem->hasIncompleteArguments();
  OS_ASSERT(!hasIncompleteArguments);

  runmanager::RubyJobBuilder rjb(*m_bclMeasure, rubyMeasure.arguments());

  openstudio::path p = getOpenStudioRubyIncludePath();
  QString arg = "-I";
  arg.append(toQString(p));
  rjb.addToolArgument(arg.toStdString());

  openstudio::runmanager::Workflow wf;
  rjb.addToWorkflow(wf);
  wf.add(co.getTools());
  wf.setInputFiles(modelPath, openstudio::path());

  m_job = wf.create(m_workingDir, modelPath);

  // DLM: you could make rm a class member then you would not have to call waitForFinished here
  runmanager::RunManager rm;
  bool queued = rm.enqueue(*m_job, true);
  OS_ASSERT(queued);
  std::vector<runmanager::Job> jobs = rm.getJobs();
  OS_ASSERT(jobs.size() == 1);
  rm.waitForFinished ();

  QTimer::singleShot(0, this, SLOT(displayResults()));
}
void LocalLibraryController::showMyMeasuresFolder()
{
  openstudio::path userMeasuresDir = BCLMeasure::userMeasuresDir();
  QString path = QDir::toNativeSeparators(toQString(userMeasuresDir));
  QDesktopServices::openUrl(QUrl("file:///" + path));
}