Example #1
0
GenGraphForm::GenGraphForm()
: currentTask(NULL), settingFilter(false)
{
    // signals and slots connections
    connect(browseButton, SIGNAL(clicked()), this, SLOT(doBrowse()));
    connect(exportButton, SIGNAL(clicked()), this, SLOT(doExport()));
    connect(displayButton, SIGNAL(clicked()), this, SLOT(doDisplay()));
    connect(closeButton, SIGNAL(clicked()), this, SLOT(doClose()));
    connect(filename, SIGNAL(textChanged(const QString&)), this, SLOT(change()));
    connect(presetFilter, SIGNAL(activated(const QString&)), this, SLOT(setFilter()));
    connect(showNodes, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showObjects, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showBehaviorModels, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showCollisionModels, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showVisualModels, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showMappings, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showContext, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showCollisionPipeline, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showSolvers, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showMechanicalStates, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showForceFields, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showInteractionForceFields, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showConstraints, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showMass, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showTopology, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));
    connect(showMechanicalMappings, SIGNAL(toggled(bool)), this, SLOT(changeFilter()));

    // init preset filters
	{
		std::set<std::string>& filt = presetFilters["Full Graph"];
		filt.insert("showNodes");
		filt.insert("showObjects");
		filt.insert("showBehaviorModels");
		filt.insert("showCollisionModels");
		filt.insert("showVisualModels");
		filt.insert("showMappings");
		filt.insert("showContext");
		filt.insert("showCollisionPipeline");
		filt.insert("showSolvers");
		filt.insert("showMechanicalStates");
		filt.insert("showForceFields");
		filt.insert("showInteractionForceFields");
		filt.insert("showConstraints");
		filt.insert("showMass");
		filt.insert("showTopology");
		filt.insert("showMechanicalMappings");
	}
	{
		std::set<std::string>& filt = presetFilters["All Objects"];
		filt = presetFilters["Full Graph"];
		filt.erase("showNodes");
	}
	{
		std::set<std::string>& filt = presetFilters["All Nodes"];
		filt.insert("showNodes");
	}
	{
		std::set<std::string>& filt = presetFilters["Mechanical Graph"];
		filt = presetFilters["Full Graph"];
		filt.erase("showCollisionModels");
		filt.erase("showVisualModels");
		filt.erase("showMappings");
		filt.erase("showCollisionPipeline");
	}
	{
		std::set<std::string>& filt = presetFilters["Mechanical Objects"];
		filt = presetFilters["Mechanical Graph"];
		filt.erase("showNodes");
	}
	{
		std::set<std::string>& filt = presetFilters["Visual Graph"];
		filt.insert("showNodes");
		filt.insert("showObjects");
		filt.insert("showVisualModels");
	}
	{
		std::set<std::string>& filt = presetFilters["Visual Objects"];
		filt = presetFilters["Visual Graph"];
		filt.erase("showNodes");
	}
	{
		std::set<std::string>& filt = presetFilters["Collision Graph"];
		filt.insert("showNodes");
		filt.insert("showObjects");
		filt.insert("showCollisionModels");
		filt.insert("showCollisionPipeline");
	}
	{
		std::set<std::string>& filt = presetFilters["Collision Objects"];
		filt = presetFilters["Collision Graph"];
		filt.erase("showNodes");
	}
	{
		std::set<std::string>& filt = presetFilters["Collision Response Graph"];
		filt.insert("showNodes");
		filt.insert("showObjects");
		//filt.insert("showBehaviorModels");
		filt.insert("showCollisionModels");
		//filt.insert("showVisualModels");
		//filt.insert("showMappings");
		//filt.insert("showContext");
		//filt.insert("showCollisionPipeline");
		filt.insert("showSolvers");
		filt.insert("showMechanicalStates");
		//filt.insert("showForceFields");
		filt.insert("showInteractionForceFields");
		filt.insert("showConstraints");
		//filt.insert("showMass");
		//filt.insert("showTopology");
		filt.insert("showMechanicalMappings");
	}
	{
		std::set<std::string>& filt = presetFilters["Collision Response Objects"];
		filt = presetFilters["Collision Response Graph"];
		filt.erase("showNodes");
	}

}
void LDViewExportOption::populate(void)
{
	QWidget *parent;
	parent = m_box;
    LDExporterSettingList &settings = m_exporter->getSettings();
    LDExporterSettingList::iterator it;

	if (m_box != NULL)
	{
//		scrollArea->removeChild(m_box);
		scrollArea->adjustSize();
		delete m_box;
	}
	m_box = new QWidget(scrollArea);
	m_box->setObjectName("m_box");
	m_lay = new QVBoxLayout();
	m_lay->setObjectName("m_lay");
	m_lay->setMargin(11);
	m_lay->setSpacing(4);
	m_box->setLayout(m_lay);
	QVBoxLayout *vbl= NULL;
    std::stack<int> groupSizes;
	std::stack<QWidget *> parents;
    int groupSize = 0;
    for (it = settings.begin(); it != settings.end(); it++)
    {
        bool inGroup = groupSize > 0;

        if (groupSize > 0)
        {
            groupSize--;
            if (groupSize == 0)
            {
                // We just got to the end of a group, so pop the previous
                // groupSize value off the groupSizes stack.
                groupSize = groupSizes.top();
                groupSizes.pop();
				parent = parents.top();
				parents.pop();
//				vbl = new QVBoxLayout(parent->layout());
				//vbl = NULL;
            }
        }
        if (it->getGroupSize() > 0)
        {
            // This item is the start of a group.
            if (inGroup)
            {
                // At the beginning of this iteration we were in a group, so
                // use a bool setting instead of a group setting.
				QString qstmp;
				ucstringtoqstring(qstmp,it->getName());

				QCheckBox *check;
				check = new QCheckBox(qstmp,parent);
				check->setObjectName(qstmp);
				check->setChecked(it->getBoolValue());
				m_settings[&*it] = check;
				if (vbl)
				{
					vbl->addWidget(check);
					m_groups[vbl][&*it] = check;
				}
            }
            else
            {
                // Top level group; use a group setting.
				if (vbl)
				{
                	QSpacerItem *sp = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
                	QHBoxLayout *hbox;
                	QPushButton *rg;
                	hbox = new QHBoxLayout();
                	rg = new QPushButton("Reset Group");
                	hbox->addItem(sp);
                	hbox->addWidget(rg);
					rg->setObjectName("Reset Group");
                	vbl->addLayout(hbox);
					connect( rg, SIGNAL( clicked() ), this, SLOT( doResetGroup() ) );
				}
				QString qstmp;
				ucstringtoqstring(qstmp,it->getName());
				QGroupBox *gb;
				gb = new QGroupBox (qstmp, m_box);
				gb->setObjectName(qstmp);
				m_lay->addWidget(gb);
				vbl = new QVBoxLayout(gb);
				gb->setLayout(vbl);
				parent=gb;
				if (it->getType() == LDExporterSetting::TBool)
				{
					gb->setCheckable(true);
					gb->setChecked(it->getBoolValue());
					m_settings[&*it] = gb;
					m_groups[vbl][&*it] = gb;
				}
            }
			parents.push(parent);
            // We're now in a new group, so push the current groupSize onto
            // the groupSizes stack.
            groupSizes.push(groupSize);
            // Update groupSize based on the new group's size.
            groupSize = it->getGroupSize();
        }
        else
        {
            // This setting isn't the start of a group; add the appropriate type
            // of option UI to the canvas.
			QString qstmp;
			ucstringtoqstring(qstmp,it->getName());
			QHBoxLayout *hbox;
			QVBoxLayout *vbox;
			QLineEdit *li;
			QLabel *label;
			QHBoxLayout *hbox2;
			QCheckBox *check;
			hbox = new QHBoxLayout();
			hbox->setSpacing(4);
            switch (it->getType())
            {
            case LDExporterSetting::TBool:
				check = new QCheckBox(qstmp);
				check->setChecked(it->getBoolValue());
				check->setObjectName(qstmp);
				hbox->addWidget(check);
				m_settings[&*it] = check;
				if (vbl != NULL)
				{
					m_groups[vbl][&*it] = check;
				}
                break;
            case LDExporterSetting::TFloat:
            case LDExporterSetting::TLong:
				// Long and float are intentionally handeled the same.
				label = new QLabel(qstmp);
				label->setObjectName(qstmp);
				hbox->addWidget(label);
				li = new QLineEdit(qstmp);
				li->setObjectName(qstmp);
				hbox->addWidget(li);
				ucstringtoqstring(qstmp,it->getStringValue());
				li->setText(qstmp);
				m_settings[&*it] = li;
				if (vbl != NULL)
				{
					m_groups[vbl][&*it] = li;
				}
                break;
            case LDExporterSetting::TString:
				vbox = new QVBoxLayout();
				vbox->setSpacing(4);
				hbox->addLayout(vbox);
				label = new QLabel(qstmp);
				vbox->addWidget(label);
				hbox2 = new QHBoxLayout();
				hbox2->setSpacing(4);
				vbox->addLayout(hbox2);
				li = new QLineEdit(qstmp);
				hbox2->addWidget(li);
				ucstringtoqstring(qstmp,it->getStringValue());
				li->setText(qstmp);
				m_settings[&*it] = li;
				if (vbl != NULL)
				{
					m_groups[vbl][&*it] = li;
				}
				if (it->isPath())
				{
					QPushButton *but = new QPushButton();
					but->setText(TCObject::ls("LDXBrowse..."));
					hbox2->addWidget(but);
					connect( but, SIGNAL( clicked() ), this, SLOT( doBrowse()));
					m_button[but]=li;
				}
                break;
            case LDExporterSetting::TEnum:
				vbox = new QVBoxLayout();
				vbox->setSpacing(4);
				hbox->addLayout(vbox);
                label = new QLabel(qstmp);
		vbox->addWidget(label);
				QComboBox *combo;
				combo = new QComboBox();
				vbox->addWidget(combo);
				for (size_t i = 0; i < it->getOptions().size(); i++)
				{
					ucstringtoqstring(qstmp,it->getOptions()[i]);
					combo->addItem(qstmp);
				}
				combo->setCurrentIndex(it->getSelectedOption());
				m_settings[&*it] = combo;
				if (vbl != NULL)
				{
					m_groups[vbl][&*it] = combo;
				}
                break;
            default:
                throw "not implemented";
            }
			if (it->getTooltip().size() > 0)
			{
				ucstringtoqstring(qstmp, it->getTooltip());
				//QToolTip::add(hbox, qstmp);
			}
			if (vbl) vbl->addLayout(hbox);
        }
	}
    if (vbl)
    {
        QSpacerItem *sp = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
        QHBoxLayout *hbox;
        QPushButton *rg;
        hbox = new QHBoxLayout();
        rg = new QPushButton("Reset Group");
		rg->setObjectName("Reset Group");
        hbox->addItem(sp);
        hbox->addWidget(rg);
        vbl->addLayout(hbox);
		connect( rg, SIGNAL( clicked() ), this, SLOT( doResetGroup() ) );
    }

	m_lay->addStretch();
	scrollArea->setWidget(m_box);
	m_box->adjustSize();
	scrollArea->adjustSize();
//	resize(width() + m_box->width() - scrollArea->visibleWidth(), height());
	setFixedWidth(width());
}