Changeset 1025 for trunk/modelicaml


Ignore:
Timestamp:
09/27/11 20:19:00 (13 years ago)
Author:
wschamai
Message:
  • added option for generating code before the execution of verification models
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modelicaml/org.openmodelica.modelicaml.simulation/src/org/openmodelica/modelicaml/simulation/handlers/GenerateTestSiMDataAction.java

    r953 r1025  
    6666import org.eclipse.emf.transaction.TransactionalEditingDomain;
    6767import org.eclipse.jface.dialogs.IDialogConstants;
     68import org.eclipse.jface.dialogs.MessageDialog;
    6869import org.eclipse.papyrus.core.services.ServiceException;
    6970import org.eclipse.papyrus.core.services.ServicesRegistry;
     
    7980import org.eclipse.uml2.uml.NamedElement;
    8081import org.openmodelica.modelicaml.common.constants.Constants;
    81 import org.openmodelica.modelicaml.common.helpers.TestExecutionServices;
     82import org.openmodelica.modelicaml.common.helpers.VerificationExecutionServices;
    8283import org.openmodelica.modelicaml.common.services.ElementsCollector;
    8384import org.openmodelica.modelicaml.simulation.testexecution.actions.ExecuteTestsAction;
     
    147148       
    148149        // Set a time stamp that is used for names
    149         TestExecutionServices.setDate();
     150        VerificationExecutionServices.setDate();
    150151       
    151152        // Set the folder paths
     
    154155        IProject iProject = root.getProject(projectName);
    155156        projectAbsolutePath = iProject.getLocationURI().toString().replaceFirst("file:\\/", "");
    156         testSessionFolderAbsolutePath = projectAbsolutePath+"/"+Constants.folderName_test_gen+"/"+Constants.folderName_test_session+"_"+TestExecutionServices.getTimeStamp("");
    157        
    158         TestExecutionServices.setTestSessionFolderAbsolutePath(testSessionFolderAbsolutePath);
    159         TestExecutionServices.setProjectFolderAbsolutePath(projectAbsolutePath);
    160         TestExecutionServices.setProjectName(projectName);
     157        testSessionFolderAbsolutePath = projectAbsolutePath+"/"+Constants.folderName_verification_gen+"/"+Constants.folderName_verification_session+"_"+VerificationExecutionServices.getTimeStamp("");
     158       
     159        VerificationExecutionServices.setTestSessionFolderAbsolutePath(testSessionFolderAbsolutePath);
     160        VerificationExecutionServices.setProjectFolderAbsolutePath(projectAbsolutePath);
     161        VerificationExecutionServices.setProjectName(projectName);
    161162       
    162163        // set the list of simulation models to be executed.
     
    173174        }
    174175       
    175         if (rootModel != null && TestExecutionServices.testModels != null && TestExecutionServices.testModels.size() > 0) {
    176             org.eclipse.emf.common.util.URI chainURI = org.eclipse.emf.common.util.URI.createPlatformPluginURI(
    177                     "/org.openmodelica.modelicaml.gen.modelica/bin/sim_test_models_data_generation.chain",
    178                     true);
    179            
    180             ResourceSet rs = new ResourceSetImpl();
    181             Resource r = (Resource) rs.createResource(chainURI);
    182            
    183             try {
    184                 r.load(null);
    185             } catch (IOException e1) {
    186                 // TODO Auto-generated catch block
    187                 e1.printStackTrace();
    188             }
    189        
    190             myChain = (CChain) r.getContents().get(0);
    191        
    192             String modelFilePath = modelFileURI.replace("platform:/resource/", "");
    193             String outputFolderPath = projectName;
    194             String logPath = projectName + "/errors.log";
    195        
    196             // Don't create Parameter Files... simply set the correct path into them
    197             EList<File> files = myChain.getParametersFiles();
    198             for (File file : files) {
    199                 if (file instanceof CModel) {
    200                     file.setPath(modelFilePath);
    201                 } else if (file instanceof CFolder) {
    202                     file.setPath(outputFolderPath);
    203                 } else if (file instanceof CLog) {
    204                     file.setPath(logPath);
     176        if (rootModel != null && VerificationExecutionServices.testModels != null && VerificationExecutionServices.testModels.size() > 0) {
     177           
     178            org.eclipse.emf.common.util.URI chainURI = null;
     179           
     180            boolean generateCode = MessageDialog.openQuestion(new Shell(),
     181                    "Save Model and Generate Modelica Code?",
     182                    "Save the ModelicaML model and generate Modelica code before starting the verification models execution?");
     183           
     184            if (generateCode) {
     185                try {
     186                    // TODO: find the right Papyrus API to save the model in editor and not only the uml file!
     187                    umlModel.saveModel();
     188                    chainURI = org.eclipse.emf.common.util.URI.createPlatformPluginURI(
     189                            "/org.openmodelica.modelicaml.gen.modelica/bin/verification_models_data_generation_with_cg.chain",
     190                            true);
     191                } catch (IOException e) {
     192                    // TODO Auto-generated catch block
     193                    e.printStackTrace();
    205194                }
    206195            }
    207        
    208             Job job = new Job("Test Simulation Models Data Generation") {
    209                 protected IStatus run(IProgressMonitor monitor) {
    210                     runchain(monitor);
    211                     return Status.OK_STATUS;
     196            else {
     197                chainURI = org.eclipse.emf.common.util.URI.createPlatformPluginURI(
     198                "/org.openmodelica.modelicaml.gen.modelica/bin/verification_models_data_generation.chain",
     199                true);
     200            }
     201
     202            if (chainURI != null) {
     203                ResourceSet rs = new ResourceSetImpl();
     204                Resource r = (Resource) rs.createResource(chainURI);
     205               
     206                try {
     207                    r.load(null);
     208                } catch (IOException e1) {
     209                    // TODO Auto-generated catch block
     210                    e1.printStackTrace();
    212211                }
    213             };
    214            
    215             job.addJobChangeListener(jobChangeAdapter);
    216             job.setUser(true);
    217             job.schedule(); // run the chain and models execution
    218 
    219         }
    220        
    221         CompoundCommand cc = new CompoundCommand("Test Simulation Models Data Generation");
     212           
     213                myChain = (CChain) r.getContents().get(0);
     214           
     215                String modelFilePath = modelFileURI.replace("platform:/resource/", "");
     216                String outputFolderPath = projectName;
     217                String logPath = projectName + "/errors.log";
     218           
     219                // Don't create Parameter Files... simply set the correct path into them
     220                EList<File> files = myChain.getParametersFiles();
     221                for (File file : files) {
     222                    if (file instanceof CModel) {
     223                        file.setPath(modelFilePath);
     224                    } else if (file instanceof CFolder) {
     225                        file.setPath(outputFolderPath);
     226                    } else if (file instanceof CLog) {
     227                        file.setPath(logPath);
     228                    }
     229                }
     230           
     231                Job job = new Job("Verification Models Data Generation") {
     232                    protected IStatus run(IProgressMonitor monitor) {
     233                        runchain(monitor);
     234                        return Status.OK_STATUS;
     235                    }
     236                };
     237               
     238                job.addJobChangeListener(jobChangeAdapter);
     239                job.setUser(true);
     240                job.schedule(); // run the chain and models execution
     241            }
     242            else {
     243                MessageDialog.openError(new Shell(), "Error", "Could not save the model and load the generation chain...");
     244            }
     245        }
     246       
     247        CompoundCommand cc = new CompoundCommand("Verification Models Data Generation");
    222248        return (cc.unwrap());
    223249    }
     
    226252    public void setTestModels(Element rootModel){
    227253        ElementsCollector ec = new ElementsCollector();
    228         ec.collectElementsFromModel(rootModel, Constants.stereotypeQName_Test);
     254        ec.collectElementsFromModel(rootModel, Constants.stereotypeQName_VerificationModel);
    229255       
    230256        SelectTestSimulationModelsToExecuteDialog dialog = new SelectTestSimulationModelsToExecuteDialog(new Shell(), ec.getElements());
     
    233259        if (dialog.getReturnCode() == IDialogConstants.OK_ID) {
    234260           
    235             TestExecutionServices.testModels.clear();
     261            VerificationExecutionServices.testModels.clear();
    236262           
    237263            for (Element element : dialog.getUserSelectedTestSimulationModels()) {
    238264                if (element instanceof NamedElement) {
    239                     TestExecutionServices.testModels.add((NamedElement) element);
     265                    VerificationExecutionServices.testModels.add((NamedElement) element);
    240266                }
    241267            }
     
    309335           
    310336            IFileSystem fileSystem = EFS.getLocalFileSystem();
    311             IFileStore codeGenDir = fileSystem.getStore(URI.create(TestExecutionServices.projectAbsolutePath + "/" + Constants.folderName_code_gen));
    312             IFileStore testSessionCodeGenDir = fileSystem.getStore(URI.create(TestExecutionServices.testSessionFolderAbsolutePath + "/" + Constants.folderName_code_gen));
     337            IFileStore codeGenDir = fileSystem.getStore(URI.create(VerificationExecutionServices.projectAbsolutePath + "/" + Constants.folderName_code_gen));
     338            IFileStore testSessionCodeGenDir = fileSystem.getStore(URI.create(VerificationExecutionServices.testSessionFolderAbsolutePath + "/" + Constants.folderName_code_gen));
    313339           
    314340//          if (codeGenDir != null ) {
Note: See TracChangeset for help on using the changeset viewer.