private void SetTargetLayer() { try { if (m_schematicLayer == null) { IExtension extention = null; IExtensionManager extensionManager; extensionManager = (IExtensionManager)m_app; extention = extensionManager.FindExtension("SchematicUI.SchematicExtension"); if (extention == null) { Enabled = false; } else { m_schematicExtension = extention; ISchematicTarget target = m_schematicExtension as ISchematicTarget; if (target != null) { m_schematicLayer = target.SchematicTarget; } } } } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }
private void ProcessMaps() { IMaps Maps = ArcMap.Document.Maps; // get the Maps long lNbMaps = Maps.Count; int i = 0; for (i = 0; i < lNbMaps; i++) { IMap Map = Maps.get_Item(i); if (Map == null) { continue; } // browse its layers for a schematic layer IEnumLayer Layers = Map.get_Layers(null, false); ILayer Layer = null; Layers.Reset(); while ((Layer = Layers.Next()) != null) { ISchematicLayer schLayer = (ISchematicLayer)Layer; Updatecontainers(schLayer); } } }
// The execute part of the algorithm public void Execute(ISchematicLayer schematicLayer, ITrackCancel CancelTracker) { if (schematicLayer == null) { return; } // Before Execute part ISchematicInMemoryDiagram inMemoryDiagram; inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram; // Core algorithm InternalExecute(schematicLayer, inMemoryDiagram, CancelTracker); // Release the COM objects if (inMemoryDiagram != null) { while (System.Runtime.InteropServices.Marshal.ReleaseComObject(inMemoryDiagram) > 0) { } } while (System.Runtime.InteropServices.Marshal.ReleaseComObject(schematicLayer) > 0) { } }
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { if (e.button != 2) { return; } esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; //Determine what kind of item is selected m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); //Ensure the item gets selected if (item == esriTOCControlItem.esriTOCControlItemMap) { m_tocControl.SelectItem(map, null); } else { m_tocControl.SelectItem(layer, null); } //Set the layer into the CustomProperty (this is used by the custom layer commands) m_mapControl.CustomProperty = layer; ISchematicLayer schLayer = layer as ISchematicLayer; if (schLayer != null) /// attach menu for SchematicLayer { ISchematicTarget schematicTarget = new ESRI.ArcGIS.SchematicControls.EngineSchematicEnvironmentClass() as ISchematicTarget; if (schematicTarget != null) { schematicTarget.SchematicTarget = schLayer; } //Popup the correct context menu if (item == esriTOCControlItem.esriTOCControlItemLayer) { m_menuSchematicLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd); } } else /// attach menu for Layer { //Popup the correct context menu if (item == esriTOCControlItem.esriTOCControlItemLayer) { m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd); } } }
/////////////////////////////////////////////////////////////////////////////////////// // // ISchematicAlgorithm interface : Defines its properties and methods (mandatory) // #region Implements ISchematicAlgorithm public bool get_Enabled(ISchematicLayer schematicLayer) { if (schematicLayer == null) { return(false); } // an algorithm needs the diagram to be in editing mode in order to run if (!schematicLayer.IsEditingSchematicDiagram()) { return(false); } IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true); if (enumFeatures == null) { return(false); } // Count the selected nodes int iCount = 0; ISchematicFeature feature; enumFeatures.Reset(); feature = enumFeatures.Next(); while (feature != null && iCount < 2) { ISchematicInMemoryFeatureClass inMemoryFeatureClass; // just want SchematicFeatureNode inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)feature.Class; if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType) { iCount++; } feature = enumFeatures.Next(); } if (iCount == 1) { return(true); // just want one selected node } else { return(false); } }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { bool abortOperation = false; ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null; try { if (m_dockableDigit == null) { return; } if (arg != null) { m_x = arg.X; m_y = arg.Y; } if (m_dockableWindow == null) { return; } if (m_dockableWindow.IsVisible() == false) { m_dockableWindow.Show(true); } ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension; if (target != null) { m_schematicLayer = target.SchematicTarget; } if (m_schematicLayer == null) { System.Windows.Forms.MessageBox.Show("No target Layer"); return; } ISchematicInMemoryDiagram inMemoryDiagram; ISchematicInMemoryFeatureClass schematicInMemoryFeatureClass; ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer; //Get the point ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp; ESRI.ArcGIS.Display.IAppDisplay appDisplay; IScreenDisplay screenDisplay; IDisplay display; IDisplayTransformation transform; ISpatialReference spatialReference; inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram; schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram; if (schematicInMemoryFeatureClassContainer == null) { return; } mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app; if (mxApp == null) { return; } appDisplay = mxApp.Display; if (appDisplay == null) { return; } screenDisplay = appDisplay.FocusScreen; display = screenDisplay; if (display == null) { return; } transform = display.DisplayTransformation; if (transform == null) { return; } spatialReference = transform.SpatialReference; WKSPoint mapPt = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPoint; devPoint.x = m_x; devPoint.y = m_y; transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap point.SpatialReference = spatialReference; point.Project(spatialReference); point.X = mapPt.X; point.Y = mapPt.Y; schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass()); if (schematicInMemoryFeatureClass == null) { System.Windows.Forms.MessageBox.Show("Invalid Type."); return; } if (m_dockableDigit.CreateNode()) { //TestMandatoryField m_dockableDigit.btnOKPanel1.Visible = false; if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK); return; } ESRI.ArcGIS.Geometry.IGeometry geometry; ISchematicInMemoryFeature schematicInMemoryFeatureNode; geometry = point; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, ""); //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureNode; m_dockableDigit.FillValue(ref schematicFeature); if (m_dockableDigit.AutoClear()) { m_dockableDigit.SelectionChanged(); } } else { m_dockableDigit.btnOKPanel2.Visible = false; //Get the Tolerance of ArcMap Double tolerance; IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document; ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPt; tolerance = mxDocument.SearchTolerancePixels; devPt.x = (int)tolerance; devPt.y = (int)tolerance; transform.TransformCoords(ref point2, ref devPt, 1, 2); //2 <-> esriTransformSize 4 <-> esriTransformToMap tolerance = point2.X * 5; //increase the tolerance value IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true); ISchematicFeature schematicFeatureSelected = null; double distancetmp; double distance = 0; schematicFeatures.Reset(); if (schematicFeatures.Count <= 0) { return; } //pSchematicFeatures may contain several features, we are choosing the closest node. ISchematicFeature schematicFeature2 = schematicFeatures.Next(); double dX; double dY; ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode = null; if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) { schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } } ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode; dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; schematicFeatureSelected = schematicFeature2; distance = SquareDistance(dX - point.X, dY - point.Y); while (schematicFeature2 != null) { //find the closest featureNode... if (schematicInMemoryFeatureNode != null) { schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode; if (schematicInMemoryFeatureNodeGeometry == null) { continue; } dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; distancetmp = SquareDistance(dX - point.X, dY - point.Y); if (distancetmp < distance) { distance = distancetmp; schematicFeatureSelected = schematicFeature2; } } schematicFeature2 = schematicFeatures.Next(); if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) { schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } } } if (schematicFeatureSelected == null) { return; } if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType) { return; } if (m_schematicFeature1 == null) { m_schematicFeature1 = schematicFeatureSelected; m_dockableDigit.SchematicFeature1(m_schematicFeature1); if (!m_dockableDigit.CheckValidFeature(true)) { m_schematicFeature1 = null; m_dockableDigit.SchematicFeature1(m_schematicFeature1); throw new Exception("Invalid starting node for this link type"); } //Begin Feedback m_linkFbk = new NewLineFeedback(); m_linkFbk.Display = screenDisplay; //symbol ISimpleLineSymbol sLnSym; IRgbColor rGB = new RgbColor(); sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol; //Make a color rGB.Red = 255; rGB.Green = 0; rGB.Blue = 0; // Setup the symbol with color and style sLnSym.Color = rGB; m_linkFbk.Start(point); //End Feedback //To know if we are in the same diagram. m_schematicLayerForLink = m_schematicLayer; } else { if (m_schematicLayerForLink != m_schematicLayer) { System.Windows.Forms.MessageBox.Show("wrong Target layer"); m_schematicLayerForLink = null; EndFeedBack(); return; } m_schematicFeature2 = schematicFeatureSelected; m_dockableDigit.SchematicFeature2(m_schematicFeature2); //TestMandatoryField if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK); return; } if (!m_dockableDigit.CheckValidFeature(false)) { m_schematicFeature2 = null; m_dockableDigit.SchematicFeature2(m_schematicFeature2); throw new Exception("Invalid End node for this link type"); } //CreateLink ISchematicInMemoryFeature schematicInMemoryFeatureLink; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, ""); //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureLink; m_dockableDigit.FillValue(ref schematicFeature); //End Feedback EndFeedBack(); m_schematicLayerForLink = null; if (m_dockableDigit.AutoClear()) { m_dockableDigit.SelectionChanged(); } } } //Refresh the view and viewer windows RefreshView(); } catch (System.Exception e) { if (abortOperation && (schematicOperation != null)) { schematicOperation.AbortOperation(); } EndFeedBack(); System.Windows.Forms.MessageBox.Show(e.Message); } return; }
private void timerAutoRefresh_Tick(object sender, EventArgs e) { if (m_schematicInMemoryDiagram != null && this.AutoOn.Checked) { timerAutoRefresh.Stop(); m_schematicInMemoryDiagram.Refresh(); ILayer layer; IDocument doc; IMxDocument mxDoc; IMaps maps; IEnumLayer enumLayers; IMap map; ISchematicLayer schematicLayer = null; doc = m_application.Document; mxDoc = doc as IMxDocument; if (mxDoc == null) return; maps = mxDoc.Maps; for (int i = 0; i < maps.Count; i++) { map = maps.get_Item(i); enumLayers = map.get_Layers(null, true); enumLayers.Reset(); layer = enumLayers.Next(); while (layer != null) { string sText = layer.Name; try { if (layer is ISchematicLayer) { schematicLayer = (ISchematicLayer)layer; if (schematicLayer.SchematicInMemoryDiagram != null) { if (schematicLayer.SchematicInMemoryDiagram == m_schematicInMemoryDiagram) break; } else if (sText == m_schematicInMemoryDiagram.Name) break; } } finally { layer = null; } schematicLayer = null; layer = enumLayers.Next(); } if (schematicLayer != null) { IActiveView actiView; actiView = (IActiveView)map; actiView.Refresh(); } } RefreshViewerWindows(); timerAutoRefresh.Start(); } }
public void Init(ISchematicLayer schematicLayer) { // CR229717: Lost the ElementClass if the dockable window is deactivate if (schematicLayer == m_schematicLayer) if (m_schEltClass != null) return; try { if (schematicLayer == null) return; m_schematicLayer = schematicLayer; XmlNode col = null; String myString = ""; m_schDataset = schematicLayer.SchematicDiagram.SchematicDiagramClass.SchematicDataset; m_schEltClassCont = (ISchematicElementClassContainer)m_schDataset; m_SchematicInMemoryDiagram = schematicLayer.SchematicInMemoryDiagram; m_dom = new XmlDocument(); ISchematicDiagram schematicDiagram; schematicDiagram = m_SchematicInMemoryDiagram.SchematicDiagram; // get the path of the xml file that contains the definitions of the digitize dockable window String path; ISchematicDiagramClass schematicDiagramClass = schematicDiagram.SchematicDiagramClass; ISchematicAttributeContainer schematicAttributeContainer = (ISchematicAttributeContainer)schematicDiagramClass; ISchematicAttribute schematicAttribute = schematicAttributeContainer.GetSchematicAttribute("DigitizePropertiesLocation", true); if (schematicAttribute == null) { System.Windows.Forms.MessageBox.Show("Need an attribute named DigitizePropertiesLocation in the corresponding DiagramTemplate attributes"); return; } path = (string)schematicAttribute.GetValue((ISchematicObject)schematicDiagram); if (IsRelative(path)) //Concat the workspace's path with this path { //current workspace path ISchematicDataset myDataset = schematicDiagramClass.SchematicDataset; if (myDataset != null) { ISchematicWorkspace mySchematicWorkspace = myDataset.SchematicWorkspace; if (mySchematicWorkspace != null) { ESRI.ArcGIS.Geodatabase.IWorkspace myWorkspace = mySchematicWorkspace.Workspace; if (myWorkspace != null) { string workspacePath = myWorkspace.PathName; //add "..\" to path to step back one level... string stepBack = "..\\"; path = stepBack + path; path = System.IO.Path.Combine(workspacePath, path); } } } } //else keep the original hard path XmlReader reader = XmlReader.Create(path); m_dom.Load(reader); //Load Nodes XmlNodeList nodes = m_dom.SelectNodes("descendant::NodeFeature"); //Clear combo box after each call cboNodeType.Items.Clear(); foreach (XmlElement node in nodes) { cboNodeType.Items.Add(node.GetAttribute("FeatureClassName").ToString()); } //Load Links XmlNodeList links = m_dom.SelectNodes("descendant::LinkFeature"); //Clear combo box after each call cboLinkType.Items.Clear(); foreach (XmlElement link in links) { cboLinkType.Items.Add(link.GetAttribute("FeatureClassName").ToString()); } col = m_dom.SelectSingleNode("descendant::MandatoryColor"); if (col != null) { myString = "System.Drawing."; myString = col.InnerText.ToString(); m_MandatoryColor = System.Drawing.Color.FromName(myString); } col = m_dom.SelectSingleNode("descendant::FormName"); if (col != null) { myString = col.InnerText.ToString(); Text = myString; } XmlNodeList rels = m_dom.SelectNodes("descendant::Relation"); if (rels.Count > 0) m_relations = rels; col = m_dom.SelectSingleNode("descendant::AutoClearAfterCreate"); if ((col != null) && col.InnerText.ToString() == "True") m_autoClear = true; } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } m_Panel1 = Splitter.Panel1; m_Panel2 = Splitter.Panel2; m_curPanel = Splitter.Panel1; lblMode.Text = "Create Node"; m_loading = false; m_clickPanel = false; m_schEltClass = null; }
// The execute part of the algorithm private void InternalExecute(ISchematicLayer schematicLayer, ISchematicInMemoryDiagram inMemoryDiagram, ITrackCancel CancelTracker) { if (schematicLayer == null || inMemoryDiagram == null) return; // get the diagram spatial reference for geometry transformation IGeoDataset geoDataset = (IGeoDataset)inMemoryDiagram; if (geoDataset == null) return; ISpatialReference spatialReference = geoDataset.SpatialReference; ISchematicDiagramClass diagramClass; diagramClass = inMemoryDiagram.SchematicDiagramClass; if (diagramClass == null) return; ISchematicDataset schemDataset; schemDataset = diagramClass.SchematicDataset; if (schemDataset == null) return; ISchematicAlgorithmEventsTrigger algorithmEventsTrigger; algorithmEventsTrigger = (ISchematicAlgorithmEventsTrigger)schemDataset; if (algorithmEventsTrigger == null) return; ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)schematicLayer; ISchematicAlgorithm algorithm = (ISchematicAlgorithm)this; bool canExecute = true; algorithmEventsTrigger.FireBeforeExecuteAlgorithm(layer, algorithm, ref canExecute); if (!canExecute) return; // cannot execute // Get the selected Features IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true); if (enumFeatures == null) return; // Count the selected nodes ISchematicInMemoryFeatureClass inMemoryFeatureClass; ISchematicFeature selectedFeature = null; int iCount = 0; ISchematicFeature schemFeature; enumFeatures.Reset(); schemFeature = enumFeatures.Next(); while (schemFeature != null && iCount < 2) { // just want SchematicFeatureNode inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)schemFeature.Class; if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType) { selectedFeature = schemFeature; iCount++; } schemFeature = enumFeatures.Next(); } if (iCount != 1 || selectedFeature == null) return; // must be only one // Create a new SchematicAnalystFindConnected algorithm ISchematicAnalystFindConnected analystFindConnected = null; analystFindConnected = (ISchematicAnalystFindConnected)new SchematicAnalystFindConnected(); if (analystFindConnected == null) return; // Modifying parameters value for this SchematicAnalystFindConnected algorithm so that when it is launched the trace result appears a selection set{ analystFindConnected.SelectLink = true; analystFindConnected.SelectNode = true; analystFindConnected.UseFlow = false; //pAnalystFindConnected.FlowDirection = 1; // Execute the algorithm analystFindConnected.Execute(schematicLayer, CancelTracker); // Retrieving the trace result (if any) IEnumSchematicFeature resultFeatures; resultFeatures = analystFindConnected.TraceResult; // free the schematic analyst COM object while (System.Runtime.InteropServices.Marshal.ReleaseComObject(analystFindConnected) > 0) { } if (resultFeatures == null || resultFeatures.Count < 1) return; // Apply the translation to the result //ISchematicInMemoryDiagram inMemoryDiagram; //inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram; // Translating each traced elements according to the TranslationFactorX and TranslationFactorY parameters current values ISchematicInMemoryFeature inMemoryFeature; resultFeatures.Reset(); while ((inMemoryFeature = (ISchematicInMemoryFeature)resultFeatures.Next()) != null) { IGeometry geometry; ITransform2D transform; esriSchematicElementType elemType; inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)inMemoryFeature.Class; elemType = inMemoryFeatureClass.SchematicElementClass.SchematicElementType; if (elemType == esriSchematicElementType.esriSchematicLinkType || elemType == esriSchematicElementType.esriSchematicNodeType) { // get a copy of the feature geometry // then process the cloned geometry rather than the feature geometry directly // Thus the modifications are stored in the heap of the current operation // meaning it can be undone then redo (undo/redo) geometry = inMemoryFeature.ShapeCopy; // Convert the geometry into the SpatialReference of diagram class geometry.Project(spatialReference); // Move the geometry transform = (ITransform2D)geometry; if (transform != null) { transform.Move(m_paramX, m_paramY); // Convert the moved geometry into the spatial reference of storage // and feed it back to the feature IObjectClass table = inMemoryFeature.Class; if (table == null) continue; IGeoDataset featureGeoDataset = (IGeoDataset)table; if (featureGeoDataset == null) continue; ISpatialReference featureSpatialRef = featureGeoDataset.SpatialReference; if (featureSpatialRef == null) continue; IGeometry movedGeometry = (IGeometry)transform; movedGeometry.Project(featureSpatialRef); inMemoryFeature.Shape = movedGeometry; } } } // After Execute part algorithmEventsTrigger.FireAfterExecuteAlgorithm(layer, algorithm); // update the diagram extent schematicLayer.UpdateExtent(); }
// The execute part of the algorithm public void Execute(ISchematicLayer schematicLayer, ITrackCancel CancelTracker) { if (schematicLayer == null) return; // Before Execute part ISchematicInMemoryDiagram inMemoryDiagram; inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram; // Core algorithm InternalExecute(schematicLayer, inMemoryDiagram, CancelTracker); // Release the COM objects if (inMemoryDiagram != null) while (System.Runtime.InteropServices.Marshal.ReleaseComObject(inMemoryDiagram) > 0) { } while (System.Runtime.InteropServices.Marshal.ReleaseComObject(schematicLayer) > 0) { } }
/////////////////////////////////////////////////////////////////////////////////////// // // ISchematicAlgorithm interface : Defines its properties and methods (mandatory) // #region Implements ISchematicAlgorithm public bool get_Enabled(ISchematicLayer schematicLayer) { if (schematicLayer == null) return false; // an algorithm needs the diagram to be in editing mode in order to run if (!schematicLayer.IsEditingSchematicDiagram()) return false; IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true); if (enumFeatures == null) return false; // Count the selected nodes int iCount = 0; ISchematicFeature feature; enumFeatures.Reset(); feature = enumFeatures.Next(); while (feature != null && iCount < 2) { ISchematicInMemoryFeatureClass inMemoryFeatureClass; // just want SchematicFeatureNode inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)feature.Class; if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType) iCount++; feature = enumFeatures.Next(); } if (iCount == 1) return true; // just want one selected node else return false; }
private void SetTargetLayer() { try { if (m_schematicLayer == null) { IExtension extention = null; IExtensionManager extensionManager; extensionManager = (IExtensionManager)m_app; extention = extensionManager.FindExtension("SchematicUI.SchematicExtension"); if (extention == null) Enabled = false; else { m_schematicExtension = extention; ISchematicTarget target = m_schematicExtension as ISchematicTarget; if (target != null) m_schematicLayer = target.SchematicTarget; } } } catch (System.Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { bool abortOperation = false; ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null; try { if (m_dockableDigit == null) return; if (arg != null) { m_x = arg.X; m_y = arg.Y; } if (m_dockableWindow == null) return; if (m_dockableWindow.IsVisible() == false) { m_dockableWindow.Show(true); } ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension; if (target != null) m_schematicLayer = target.SchematicTarget; if (m_schematicLayer == null) { System.Windows.Forms.MessageBox.Show("No target Layer"); return; } ISchematicInMemoryDiagram inMemoryDiagram; ISchematicInMemoryFeatureClass schematicInMemoryFeatureClass; ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer; //Get the point ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp; ESRI.ArcGIS.Display.IAppDisplay appDisplay; IScreenDisplay screenDisplay; IDisplay display; IDisplayTransformation transform; ISpatialReference spatialReference; inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram; schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram; if (schematicInMemoryFeatureClassContainer == null) return; mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app; if (mxApp == null) return; appDisplay = mxApp.Display; if (appDisplay == null) return; screenDisplay = appDisplay.FocusScreen; display = screenDisplay; if (display == null) return; transform = display.DisplayTransformation; if (transform == null) return; spatialReference = transform.SpatialReference; WKSPoint mapPt = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPoint; devPoint.x = m_x; devPoint.y = m_y; transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap point.SpatialReference = spatialReference; point.Project(spatialReference); point.X = mapPt.X; point.Y = mapPt.Y; schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass()); if (schematicInMemoryFeatureClass == null) { System.Windows.Forms.MessageBox.Show("Invalid Type."); return; } if (m_dockableDigit.CreateNode()) { //TestMandatoryField m_dockableDigit.btnOKPanel1.Visible = false; if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK); return; } ESRI.ArcGIS.Geometry.IGeometry geometry; ISchematicInMemoryFeature schematicInMemoryFeatureNode; geometry = point; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, ""); //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureNode; m_dockableDigit.FillValue(ref schematicFeature); if (m_dockableDigit.AutoClear()) m_dockableDigit.SelectionChanged(); } else { m_dockableDigit.btnOKPanel2.Visible = false; //Get the Tolerance of ArcMap Double tolerance; IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document; ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPt; tolerance = mxDocument.SearchTolerancePixels; devPt.x = (int)tolerance; devPt.y = (int)tolerance; transform.TransformCoords(ref point2, ref devPt, 1, 2);//2 <-> esriTransformSize 4 <-> esriTransformToMap tolerance = point2.X * 5;//increase the tolerance value IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true); ISchematicFeature schematicFeatureSelected = null; double distancetmp; double distance = 0; schematicFeatures.Reset(); if (schematicFeatures.Count <= 0) return; //pSchematicFeatures may contain several features, we are choosing the closest node. ISchematicFeature schematicFeature2 = schematicFeatures.Next(); double dX; double dY; ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode = null; if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode; dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; schematicFeatureSelected = schematicFeature2; distance = SquareDistance(dX - point.X, dY - point.Y); while (schematicFeature2 != null) { //find the closest featureNode... if (schematicInMemoryFeatureNode != null) { schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry) schematicInMemoryFeatureNode; if (schematicInMemoryFeatureNodeGeometry == null) continue; dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; distancetmp = SquareDistance(dX - point.X, dY - point.Y); if (distancetmp < distance) { distance = distancetmp; schematicFeatureSelected = schematicFeature2; } } schematicFeature2 = schematicFeatures.Next(); if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } } if (schematicFeatureSelected == null) return; if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType) return; if (m_schematicFeature1 == null) { m_schematicFeature1 = schematicFeatureSelected; m_dockableDigit.SchematicFeature1(m_schematicFeature1); if (!m_dockableDigit.CheckValidFeature(true)) { m_schematicFeature1 = null; m_dockableDigit.SchematicFeature1(m_schematicFeature1); throw new Exception("Invalid starting node for this link type"); } //Begin Feedback m_linkFbk = new NewLineFeedback(); m_linkFbk.Display = screenDisplay; //symbol ISimpleLineSymbol sLnSym; IRgbColor rGB = new RgbColor(); sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol; //Make a color rGB.Red = 255; rGB.Green = 0; rGB.Blue = 0; // Setup the symbol with color and style sLnSym.Color = rGB; m_linkFbk.Start(point); //End Feedback //To know if we are in the same diagram. m_schematicLayerForLink = m_schematicLayer; } else { if (m_schematicLayerForLink != m_schematicLayer) { System.Windows.Forms.MessageBox.Show("wrong Target layer"); m_schematicLayerForLink = null; EndFeedBack(); return; } m_schematicFeature2 = schematicFeatureSelected; m_dockableDigit.SchematicFeature2(m_schematicFeature2); //TestMandatoryField if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK); return; } if (!m_dockableDigit.CheckValidFeature(false)) { m_schematicFeature2 = null; m_dockableDigit.SchematicFeature2(m_schematicFeature2); throw new Exception("Invalid End node for this link type"); } //CreateLink ISchematicInMemoryFeature schematicInMemoryFeatureLink; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, ""); //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureLink; m_dockableDigit.FillValue(ref schematicFeature); //End Feedback EndFeedBack(); m_schematicLayerForLink = null; if (m_dockableDigit.AutoClear()) m_dockableDigit.SelectionChanged(); } } //Refresh the view and viewer windows RefreshView(); } catch (System.Exception e) { if (abortOperation && (schematicOperation != null)) schematicOperation.AbortOperation(); EndFeedBack(); System.Windows.Forms.MessageBox.Show(e.Message); } return; }
// The execute part of the algorithm private void InternalExecute(ISchematicLayer schematicLayer, ISchematicInMemoryDiagram inMemoryDiagram, ITrackCancel CancelTracker) { if (schematicLayer == null || inMemoryDiagram == null) { return; } // get the diagram spatial reference for geometry transformation IGeoDataset geoDataset = (IGeoDataset)inMemoryDiagram; if (geoDataset == null) { return; } ISpatialReference spatialReference = geoDataset.SpatialReference; ISchematicDiagramClass diagramClass; diagramClass = inMemoryDiagram.SchematicDiagramClass; if (diagramClass == null) { return; } ISchematicDataset schemDataset; schemDataset = diagramClass.SchematicDataset; if (schemDataset == null) { return; } ISchematicAlgorithmEventsTrigger algorithmEventsTrigger; algorithmEventsTrigger = (ISchematicAlgorithmEventsTrigger)schemDataset; if (algorithmEventsTrigger == null) { return; } ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)schematicLayer; ISchematicAlgorithm algorithm = (ISchematicAlgorithm)this; bool canExecute = true; algorithmEventsTrigger.FireBeforeExecuteAlgorithm(layer, algorithm, ref canExecute); if (!canExecute) { return; // cannot execute } // Get the selected Features IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true); if (enumFeatures == null) { return; } // Count the selected nodes ISchematicInMemoryFeatureClass inMemoryFeatureClass; ISchematicFeature selectedFeature = null; int iCount = 0; ISchematicFeature schemFeature; enumFeatures.Reset(); schemFeature = enumFeatures.Next(); while (schemFeature != null && iCount < 2) { // just want SchematicFeatureNode inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)schemFeature.Class; if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType) { selectedFeature = schemFeature; iCount++; } schemFeature = enumFeatures.Next(); } if (iCount != 1 || selectedFeature == null) { return; // must be only one } // Create a new SchematicAnalystFindConnected algorithm ISchematicAnalystFindConnected analystFindConnected = null; analystFindConnected = (ISchematicAnalystFindConnected) new SchematicAnalystFindConnected(); if (analystFindConnected == null) { return; } // Modifying parameters value for this SchematicAnalystFindConnected algorithm so that when it is launched the trace result appears a selection set{ analystFindConnected.SelectLink = true; analystFindConnected.SelectNode = true; analystFindConnected.UseFlow = false; //pAnalystFindConnected.FlowDirection = 1; // Execute the algorithm analystFindConnected.Execute(schematicLayer, CancelTracker); // Retrieving the trace result (if any) IEnumSchematicFeature resultFeatures; resultFeatures = analystFindConnected.TraceResult; // free the schematic analyst COM object while (System.Runtime.InteropServices.Marshal.ReleaseComObject(analystFindConnected) > 0) { } if (resultFeatures == null || resultFeatures.Count < 1) { return; } // Apply the translation to the result //ISchematicInMemoryDiagram inMemoryDiagram; //inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram; // Translating each traced elements according to the TranslationFactorX and TranslationFactorY parameters current values ISchematicInMemoryFeature inMemoryFeature; resultFeatures.Reset(); while ((inMemoryFeature = (ISchematicInMemoryFeature)resultFeatures.Next()) != null) { IGeometry geometry; ITransform2D transform; esriSchematicElementType elemType; inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)inMemoryFeature.Class; elemType = inMemoryFeatureClass.SchematicElementClass.SchematicElementType; if (elemType == esriSchematicElementType.esriSchematicLinkType || elemType == esriSchematicElementType.esriSchematicNodeType) { // get a copy of the feature geometry // then process the cloned geometry rather than the feature geometry directly // Thus the modifications are stored in the heap of the current operation // meaning it can be undone then redo (undo/redo) geometry = inMemoryFeature.ShapeCopy; // Convert the geometry into the SpatialReference of diagram class geometry.Project(spatialReference); // Move the geometry transform = (ITransform2D)geometry; if (transform != null) { transform.Move(m_paramX, m_paramY); // Convert the moved geometry into the spatial reference of storage // and feed it back to the feature IObjectClass table = inMemoryFeature.Class; if (table == null) { continue; } IGeoDataset featureGeoDataset = (IGeoDataset)table; if (featureGeoDataset == null) { continue; } ISpatialReference featureSpatialRef = featureGeoDataset.SpatialReference; if (featureSpatialRef == null) { continue; } IGeometry movedGeometry = (IGeometry)transform; movedGeometry.Project(featureSpatialRef); inMemoryFeature.Shape = movedGeometry; } } } // After Execute part algorithmEventsTrigger.FireAfterExecuteAlgorithm(layer, algorithm); // update the diagram extent schematicLayer.UpdateExtent(); }