public object CreateInstance(Type type, IEnumerable <Tag> metaInfo) { try { var valueIter = new ElementEnumerator(metaInfo); valueIter.MoveNext(); int rank = int.Parse(valueIter.Current); int[] lengths = new int[rank]; int[] lowerBounds = new int[rank]; for (int i = 0; i < rank; i++) { valueIter.MoveNext(); lengths[i] = int.Parse(valueIter.Current); } for (int i = 0; i < rank; i++) { valueIter.MoveNext(); lowerBounds[i] = int.Parse(valueIter.Current); } Type elementType = type.GetElementType(); Array a = Array.CreateInstance(elementType, lengths, lowerBounds); if (a == null) { throw new PersistenceException("invalid instance data type, expected array"); } int[] positions = (int[])lowerBounds.Clone(); while (valueIter.MoveNext()) { a.SetValue(numberConverter.Parse(valueIter.Current, elementType), positions); positions[0] += 1; for (int i = 0; i < a.Rank - 1; i++) { if (positions[i] >= lengths[i] + lowerBounds[i]) { positions[i + 1] += 1; positions[i] = lowerBounds[i]; } else { break; } } } return(a); } catch (InvalidOperationException e) { throw new PersistenceException("Insuffictient data to deserialize compact array", e); } catch (InvalidCastException e) { throw new PersistenceException("Invalid element data during compact array deserialization", e); } }
public double[] ElementEnumerator_ThirdFormulaTests(int count, int firstElement, int secondElement) { double[] result = new double[count]; int i = 0; foreach (var element in ElementEnumerator <double> .GetNumbers(firstElement, secondElement, count, FormulaThird.CalculateElement)) { result[i++] = element; } return(result); }
public int[] ElementEnumerator_SecondFormulaTests(int count, int firstElement, int secondElement) { int[] result = new int[count]; int i = 0; foreach (var element in ElementEnumerator <int> .GetNumbers(firstElement, secondElement, count, FormulaSecond.CalculateElement)) { result[i++] = element; } return(result); }
public int[] ElementEnumerator_FibonacciTests(int count, int firstElement, int secondElement) { int[] result = new int[count]; int i = 0; foreach (var fibonacciNumber in ElementEnumerator <int> .GetNumbers(firstElement, secondElement, count, FormulaFibonacci.CalculateElement)) { result[i++] = fibonacciNumber; } return(result); }
public static void createRegion() { Application app = Utilities.ComApp; Point3d[] pntArray = new Point3d[4]; pntArray[0] = app.Point3dFromXY(20, -6); pntArray[1] = app.Point3dFromXY(20, 0); pntArray[2] = app.Point3dFromXY(30, 0); pntArray[3] = app.Point3dFromXY(30, -6); Point3d[] pntArray1 = new Point3d[4]; pntArray1[0] = app.Point3dFromXY(30, -6); pntArray1[1] = app.Point3dFromXY(30, 0); pntArray1[2] = app.Point3dFromXY(40, 0); pntArray1[3] = app.Point3dFromXY(40, -6); Point3d[] pntArray2 = new Point3d[4]; pntArray2[0] = app.Point3dFromXY(40, -6); pntArray2[1] = app.Point3dFromXY(40, 0); pntArray2[2] = app.Point3dFromXY(60, 0); pntArray2[3] = app.Point3dFromXY(60, -6); Point3d[] pntArray3 = new Point3d[4]; pntArray3[0] = app.Point3dFromXY(60, -6); pntArray3[1] = app.Point3dFromXY(60, 0); pntArray3[2] = app.Point3dFromXY(70, 0); pntArray3[3] = app.Point3dFromXY(70, -6); Point3d[] pntArray4 = new Point3d[4]; pntArray4[0] = app.Point3dFromXY(75, -6); pntArray4[1] = app.Point3dFromXY(75, 0); pntArray4[2] = app.Point3dFromXY(80, 0); pntArray4[3] = app.Point3dFromXY(80, -6); Point3d[] pntArray5 = new Point3d[4]; pntArray5[0] = app.Point3dFromXY(80, -6); pntArray5[1] = app.Point3dFromXY(80, 0); pntArray5[2] = app.Point3dFromXY(90, 0); pntArray5[3] = app.Point3dFromXY(90, -6); Element outerShape = app.CreateShapeElement1(null, ref pntArray, MsdFillMode.NotFilled); Element outerShape1 = app.CreateShapeElement1(null, ref pntArray1, MsdFillMode.NotFilled); Element outerShape2 = app.CreateShapeElement1(null, ref pntArray2, MsdFillMode.NotFilled); Element outerShape3 = app.CreateShapeElement1(null, ref pntArray3, MsdFillMode.NotFilled); Element outerShape4 = app.CreateShapeElement1(null, ref pntArray4, MsdFillMode.NotFilled); Element outerShape5 = app.CreateShapeElement1(null, ref pntArray5, MsdFillMode.NotFilled); Element[] shapes = new Element[] { outerShape, outerShape1, outerShape2 }; Element[] shapes1 = new Element[] { outerShape3, outerShape4, outerShape5 }; /**metoda przyjmuje dwa osobne obszary Region1 i Region2, w postaci tablicy elementów, które s¹ ³¹czone osobno * ale musz¹ byæ oba, bo je¿eli jeden jest null to nie po³¹czy tego który jest przakazany; w takim przypadku zwraca enumerator zawieraj¹cy wszystkie elementy osobno; * metoda ³¹czy ze sob¹ wszystkie elementy, które mo¿na ze sob¹ po³¹czyæ; docelowo, je¿eli Region1 i Region 2 da siê po³¹czyæ, to s¹ one ³¹czone i zwracany jest jeden region; * wszystkie elementy, których nie uda³o siê pod³¹czyæ do ¿adnego innego elementu, równie¿ s¹ zwracane * na przyk³ad, Region1 zawiera 5 elementów a Region2 cztery; w Regionie 1 styczne ze sob¹ (a zatem daje siê je po³¹czyæ ze sob¹) s¹ elementy w dwóch grupach po 2 elementy, jeden element nie styka siê z ¿adnym * w Regionie 2 s¹ to równie¿ dwie grupy; ponadto, jedna grupa w Region 1 jest styczna z jedn¹ grup¹ w Region2, tak wiêc elementy w tych grupach zostaj¹ po³¹czone ze sob¹ * w enumeratorze zwracane s¹ 3 grupy oraz jeden osobny element **/ ElementEnumerator en = app.GetRegionUnion(ref shapes1, ref shapes, null, MsdFillMode.NotFilled); Element[] c = en.BuildArrayFromContents(); app.ActiveModelReference.AddElements(c); }
private void ButtonRozdziel_Click(object sender, EventArgs e) { string iFileName = textBoxFileName.Text; StreamWriter logFile = new StreamWriter(new FileStream(iFileName.Substring(0, iFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".log", FileMode.Create), Encoding.UTF8); logFile.WriteLine("Rozdielanie pliku: {0}\n", iFileName); MicroStationDGN.Application oMstn = new MicroStationDGN.Application(); DesignFile iFile = oMstn.OpenDesignFile(iFileName, true); if (iFile.Models.Count > 1) { MessageBox.Show(@"Ilość modeli w pliku większa niż 1 !"); Application.Exit(); } ModelReference modelIn = iFile.Models[1]; foreach (Level levelIn in iFile.Levels) { string levelInName = levelIn.Name; if (levelIn.IsInUse) { logFile.WriteLine("warstwa {0}: uzywana", levelInName); File.Copy(iFileName, @"C:\temp\" + levelIn.Name + ".dgn", true); DesignFile oFile = oMstn.OpenDesignFileForProgram(@"C:\temp\" + levelIn.Name + ".dgn", false); ModelReference modelOut = oFile.Models[1]; foreach (Level levelOut in oFile.Levels) { string levelOutName = levelOut.Name; if (levelOutName != levelInName) { if (levelOut.IsInUseWithinModel(modelOut)) { ElementScanCriteria elementScanCriteriaOut = new ElementScanCriteriaClass(); elementScanCriteriaOut.ExcludeAllLevels(); elementScanCriteriaOut.IncludeLevel(levelOut); ElementEnumerator elementEnumeratorOut = modelOut.Scan(elementScanCriteriaOut); //Array elementOut = elementEnumeratorOut.BuildArrayFromContents(); while (elementEnumeratorOut.MoveNext()) { modelOut.RemoveElement(elementEnumeratorOut.Current); } } if (!levelOut.IsInUse && levelOut.Number != 0) { oFile.DeleteLevel(levelOut); } } } oFile.RewriteLevels(); oFile.Save(); oFile.Close(); } else { logFile.WriteLine("warstwa {0}: brak", levelInName); } } logFile.Close(); iFile.Close(); oMstn.Quit(); }
private void scanRecurse(ModelReference model, ElementScanCriteria criteria, bool updateImidiatly) { if (modelsCellsForUpdate_.ContainsKey(model)) { return; } var cellsToUpdateList = new List <CellElement>(); foreach (string cellName in new string[] { PenConfigVariables.CellName.Value, PenConfigVariables.CellNameOld.Value }) { criteria.IncludeOnlyCell(cellName); ElementEnumerator iter = App.ActiveModelReference.Scan(criteria); iter.Reset(); while (iter.MoveNext()) { if (!iter.Current.IsCellElement() && !iter.Current.IsCompundCell()) { continue; } bool dirty = false; CellElement cell = iter.Current.AsCellElement(); if (updateImidiatly && null == checkedCellsForUpdate_.Find( x => x.MdlElementRef() == cell.MdlElementRef())) { continue; } TFFrameListClass frameList = new TFFrameListClass(); try { if (cellName.Equals(PenConfigVariables.CellName.Value)) { //frameList.InitFromElement(cell); //process(frameList, ref dirty, updateImidiatly); } else if (cellName.Equals(PenConfigVariables.CellNameOld.Value)) { processOld(ref cell, ref dirty, updateImidiatly); // CELL frameList.InitFromElement(cell); // FRAME processOld(frameList, ref dirty, updateImidiatly); } } catch (Exception ex) { // TODO log exception continue; } if (dirty) { cellFrames_.Add(cell.MdlElementRef(), frameList); cellsToUpdateList.Add(cell); } } } if (cellsToUpdateList.Count > 0) { modelsCellsForUpdate_.Add(model, cellsToUpdateList); } foreach (Attachment attachment in model.Attachments) { if (!attachment.IsActive || !attachment.IsMissingFile || !attachment.IsMissingModel) { return; } ModelReference modelRef = App.MdlGetModelReferenceFromModelRefP(attachment.MdlModelRefP()); scanRecurse(modelRef, criteria, updateImidiatly); } }