private void saveButton_Click(object sender, EventArgs e) { string fileNameOutput = FileUtil.showFileDialog("Select Profile Definition MAX XML file", "max files (*.xml, *.max)|*.xml;*.max", fileNameMerged, false); if (string.IsNullOrEmpty(fileNameOutput)) { // Save canceled return; } List <ObjectType> objects = new List <ObjectType>(); List <RelationshipType> relationships = new List <RelationshipType>(); R2ProfileDefinition profileDef = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag; string defId = profileDef.Id; ObjectType maxDefObj = (ObjectType)profileDef.SourceObject; maxDefObj.SetTagValue("MAX::ExportDate", Util.FormatLastModified(DateTime.Now)); maxDefObj.SetTagValue("MAX::ExportFile", fileNameOutput); objects.Add(maxDefObj); foreach (DataGridViewRow row in modelsDataGridView.Rows) { R2ModelElement element = (R2ModelElement)row.Cells[1].Tag; if (element != null) { element.SaveToSource(); ObjectType maxObj = (ObjectType)element.SourceObject; maxObj.id = Guid.NewGuid().ToString(); maxObj.parentId = defId; objects.Add(maxObj); // Only create Generalization Relationship if this is a Compiler Instruction if (element.BaseElement != null) { RelationshipType maxRel = new RelationshipType(); maxRel.sourceId = maxObj.id; maxRel.destId = ((ObjectType)element.BaseElement.SourceObject).id; maxRel.type = RelationshipTypeEnum.Generalization; maxRel.typeSpecified = true; relationships.Add(maxRel); } } } // Convert to MAX model ModelType model = new ModelType(); model.exportDate = Util.FormatLastModified(DateTime.Now); model.objects = objects.ToArray(); model.relationships = relationships.ToArray(); // Save Merged profile definition as MAX XML XmlSerializer serializer = new XmlSerializer(typeof(ModelType)); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineChars = "\n"; using (XmlWriter writer = XmlWriter.Create(fileNameOutput, settings)) { serializer.Serialize(writer, model); } MessageBox.Show("Created Profile Definition MAX file.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void modelsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { // Only popup file selection for Base Model and Profiles // There are separate buttons for MergedProfile Definition (== column 1) string defaultFileName = null; switch (e.ColumnIndex) { case COLUMN_BASE_MODEL: // Ask confirmation is Base Model already loaded if (baseModel != null) { if (MessageBox.Show("This action will lose any changes to the Merged Profile that are not saved.\nAre you sure?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } defaultFileName = fileNameBaseModel; break; case COLUMN_MERGED_PROFILE: ProfileMetadataForm form = new ProfileMetadataForm(); R2ProfileDefinition profDef = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag; if (profDef != null) { form.Show(profDef); modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].HeaderText = profDef.Name; } return; case 2: if (baseModel != null) { defaultFileName = fileNameProfile1; } break; case 3: if (baseModel != null) { defaultFileName = fileNameProfile2; } break; case 4: if (baseModel != null) { defaultFileName = fileNameProfile3; } break; } if (defaultFileName != null) { string fileName = FileUtil.showFileDialog("Select input MAX XML file", "max files (*.xml, *.max)|*.xml;*.max", defaultFileName, true); if (!string.IsNullOrEmpty(fileName)) { Cursor = Cursors.WaitCursor; DataGridViewCellStyle cellStyle = new DataGridViewCellStyle { BackColor = Color.White }; switch (e.ColumnIndex) { case COLUMN_BASE_MODEL: fileNameBaseModel = fileName; ClearColumn(0); ClearColumn(1); ClearColumn(2); ClearColumn(3); ClearColumn(4); LoadBaseModelAndNewMergedProfile(); UpdateStatistics(); break; /* case COLUMN_MERGED_PROFILE: * fileNameMerged = fileName; * ClearColumn(COLUMN_MERGED_PROFILE); * LoadProfileDefinition(fileNameMerged); * break;*/ case 2: fileNameProfile1 = fileName; ClearColumn(e.ColumnIndex); LoadProfile(e.ColumnIndex, fileName, cellStyle); break; case 3: fileNameProfile2 = fileName; ClearColumn(e.ColumnIndex); LoadProfile(e.ColumnIndex, fileName, cellStyle); break; case 4: fileNameProfile3 = fileName; ClearColumn(e.ColumnIndex); LoadProfile(e.ColumnIndex, fileName, cellStyle); break; } UpdateStatistics(); Cursor = Cursors.Default; } } } else if (e.ColumnIndex != -1) { DataGridViewCell cell = modelsDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (cell.Tag is R2Section) { new SectionForm().Show((R2Section)cell.Tag); } else if (cell.Tag is R2Function) { new FunctionForm().Show((R2Function)cell.Tag); } else if (cell.Tag is R2Criterion) { new CriterionForm().Show((R2Criterion)cell.Tag); } // Update content of compare grid, content might be changed in the form updateCompareDataGridView(false, _currentRow, _currentCompareRow); } }