Esempio n. 1
0
LessThanWidget::LessThanWidget(QWidget* parent, Qt::WindowFlags f)
    : QWidget(parent, f)
{
  QLabel *explanation = new QLabel(this);
  explanation->setText("The yellow items are 'less than' the selected item according to QModelIndex::operator<().\n"
                       "The red items are greater than the selected item (i.e, not less than and not equal).");

  m_coloredTreeModel = new ColoredTreeModel(this);
  QTreeView *treeView = new QTreeView(this);
  treeView->setModel(m_coloredTreeModel);
  treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
  treeView->setSelectionMode(QTreeView::SingleSelection);

  m_coloredTreeModel->setSelectionModel(treeView->selectionModel());

  QVBoxLayout *layout = new QVBoxLayout(this);
  layout->addWidget(explanation);
  layout->addWidget(treeView);

  insertGrid(QList<int>());
  insertGrid(QList<int>() << 2);
  insertGrid(QList<int>() << 3);
  insertGrid(QList<int>() << 4);
  insertGrid(QList<int>() << 3 << 2);
  insertGrid(QList<int>() << 3 << 3);
  insertGrid(QList<int>() << 3 << 4);
}
int createRecordingChamber(vector<double> x_mm_list,
						   vector<double> y_mm_list,
						   vector<double> tilt_degrees_list,
						   vector<double> rotation_degrees_list,
						   vector<double> hole_radius_list,
						   std::string saveFilename, std::string templateFilename, bool bShutdown) {



         CoInitialize(NULL);
	
		debugPrintout("Initialize necessary Solidworks variables");
        CComPtr<ISldWorks> swApp;
        CComPtr<IModelDoc2> swModel;
        CComPtr<IModelDocExtension> swModelDocExt;
        CComPtr<IFeatureManager> swFeatureManager;
        CComPtr<ISketchManager> swSketchManager;
        CComPtr<ISelectionMgr> swSelectionMgr;

        long lErrors;
        long lWarnings;

        debugPrintout("Open SolidWorks");


        CComBSTR sAssemblyName(templateFilename.c_str());
        CComBSTR sDefaultConfiguration(L"Default");

   	    mexPrintf("Attempting to launch Solidworks and load template file...\n");
		mexEvalString("drawnow;");
        HRESULT Res = swApp.CoCreateInstance(__uuidof(SldWorks),NULL, CLSCTX_LOCAL_SERVER);
		if (Res == REGDB_E_CLASSNOTREG) {
			CoUninitialize();
			return 2;
		}
		Sleep(3000);
      try {
  
        swApp->OpenDoc6(sAssemblyName, swDocASSEMBLY, swOpenDocOptions_Silent,
                sDefaultConfiguration, &lErrors, &lWarnings, &swModel);

                handleTemplateLoadingError(lErrors);
		   	    mexPrintf("Template Loaded Successfully\n");
        }
        catch(char * error) {
			CoUninitialize();
                mexPrintf("%s\n",error);
                return 1;
        }
		mexEvalString("drawnow;");
        // Load Variables and settings

		debugPrintout("Load Variables and settings");
        swApp->get_IActiveDoc2(&swModel);
        swApp->put_UserControl(VARIANT_TRUE);
        swApp->put_Visible(VARIANT_TRUE);
        swApp->SetUserPreferenceToggle(swInputDimValOnCreate, VARIANT_FALSE);

		swModel->get_ISelectionManager(&swSelectionMgr);
        swModel->get_Extension(&swModelDocExt);
        swModel->get_FeatureManager(&swFeatureManager);
        swModel->get_SketchManager(&swSketchManager);

      


        swModel->SetAddToDB(true);


        // Insert Grid into SolidWorks Model
		debugPrintout("Generate Grid");

        insertGrid(x_mm_list, y_mm_list, tilt_degrees_list, rotation_degrees_list, hole_radius_list,
                swModel, swModelDocExt, swFeatureManager, swSketchManager);

        //std::cout << "Saving File As: " << endl << saveFilename << endl << endl;

		debugPrintout("Saving Grid");
        VARIANT_BOOL saveSuccessfulSLDPART;
		swModel->SaveAs(CComBSTR(saveFilename.c_str()), &saveSuccessfulSLDPART);

 		/*
        if (saveSuccessfulSTL && saveSuccessfulSLDPART)
                std::cout << "Save Successful" << endl << endl;
        else {
                std::cout << "Error Occured While Saving" << endl;
                return 2;
        }
		*/

        if (saveSuccessfulSLDPART)
				mexPrintf("Save Successful\n");
        else {
                mexPrintf("Error Occured While Saving\n");
                return 2;
        }
		if (bShutdown) {
			mexPrintf("Shutting down Solidworks !!\n");
			VARIANT_BOOL IncludeUnsaved = true, Retval;
			swApp->CloseAllDocuments(IncludeUnsaved, &Retval);
			swApp->ExitApp();
			//delete swApp;
		}

       swApp = NULL;
        CoUninitialize();

        return 0;
}