/// <summary> /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary> void IInitializable.Initialize() { m_mainform.Shown += (sender, e) => { // create root node. var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement); rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game"); // create Orc game object and add it to rootNode. var orc = CreateOrc(); rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc); // add a child Orc. var orcChildList = orc.GetChildList(Schema.orcType.orcChild); orcChildList.Add(CreateOrc("Child Orc1")); rootNode.InitializeExtensions(); var edContext = rootNode.Cast<GameEditingContext>(); edContext.Set(orc); // set active context and select orc object. m_contextRegistry.ActiveContext = rootNode; }; }
/// <summary> /// Returns whether two nodes can be connected. "from" and "to" refer to the corresponding /// properties in IGraphEdge, not to a dragging operation, for example.</summary> /// <param name="fromNode">"From" node</param> /// <param name="fromRoute">"From" edge route</param> /// <param name="toNode">"To" node</param> /// <param name="toRoute">"To" edge route</param> /// <returns>Whether the "from" node/route can be connected to the "to" node/route</returns> public bool CanConnect(ScriptNode fromNode, ICircuitPin fromRoute, ScriptNode toNode, ICircuitPin toRoute) { var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; return(editableGraphContainer.CanConnect(fromNode, fromRoute, toNode, toRoute)); }
/// <summary> /// Performs initialization when the adapter's node is set</summary> protected override void OnNodeSet() { m_document = DomNode.Cast <IDocument>(); m_document.DirtyChanged += document_DirtyChanged; base.OnNodeSet(); }
private bool IsContained(DomNode element, DomNode container) { if (container.Is <Circuit>()) { return(true); } if (m_moveElementBehavior == MoveElementBehavior.MoveConstrainToCursorContainment) { // since container is the drop target, the cursor must be over the container when CanMove() is called return(true); } else if (m_moveElementBehavior == MoveElementBehavior.MoveConstrainToContainerBounds) { AdaptableControl control = m_viewingContext.Cast <AdaptableControl>(); var offset = GetRelativeOffset(element.Parent.Cast <ICircuitContainer>(), container.Cast <ICircuitContainer>()); // get bound in local space var elemLocalBound = GetLocalBound(control, element.Cast <Element>()); var containerLocalBound = GetLocalBound(control, container.Cast <Element>()); elemLocalBound.Offset(offset); containerLocalBound.Location = new PointF(0, GetTitleHeight(control)); containerLocalBound.Height -= GetLabelHeight(control);// exclude bottom label area elemLocalBound.Offset(GetSubContentOffset(control)); return(containerLocalBound.Contains(elemLocalBound)); } return(false); }
/// <summary> /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary> void IInitializable.Initialize() { m_mainform.Shown += (sender, e) => { // create root node. var rootNode = new DomNode(GameSchema.gameType.Type, GameSchema.gameRootElement); rootNode.SetAttribute(GameSchema.gameType.nameAttribute, "Game"); // create Orc game object and add it to rootNode. var orc = CreateOrc(); rootNode.GetChildList(GameSchema.gameType.gameObjectChild).Add(orc); // add a child Orc. var orcChildList = orc.GetChildList(GameSchema.orcType.orcChild); orcChildList.Add(CreateOrc("Child Orc1")); rootNode.InitializeExtensions(); var edContext = rootNode.Cast <GameEditingContext>(); edContext.Set(orc); // set active context and select orc object. m_contextRegistry.ActiveContext = rootNode; }; }
private void AddNode(DomNode node) { if (node.Is <Group>()) { node.Cast <Group>().Changed += GroupChanged; } }
/// <summary> /// Disconnects the edge</summary> /// <param name="edge">Edge to disconnect</param> public void Disconnect(ScriptNodeConnection edge) { var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; editableGraphContainer.Disconnect(edge); }
/// <summary> /// Can a container be resized</summary> /// <param name="container">Container to resize</param> /// <param name="borderPart">Part of border to resize</param> /// <returns>True iff the container border can be resized</returns> bool IEditableGraphContainer <ScriptNode, ScriptNodeConnection, ICircuitPin> .CanResize(object container, DiagramBorder borderPart) { var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; return(editableGraphContainer.CanResize(container, borderPart)); }
/// <summary> /// Connects the "from" node/route to the "to" node/route by creating an IGraphEdge whose /// "from" node is "fromNode", "to" node is "toNode", etc.</summary> /// <param name="fromNode">"From" node</param> /// <param name="fromRoute">"From" edge route</param> /// <param name="toNode">"To" node</param> /// <param name="toRoute">"To" edge route</param> /// <param name="existingEdge">Existing edge that is being reconnected, or null if new edge</param> /// <returns>New edge connecting the "from" node/route to the "to" node/route</returns> public ScriptNodeConnection Connect(ScriptNode fromNode, ICircuitPin fromRoute, ScriptNode toNode, ICircuitPin toRoute, ScriptNodeConnection existingEdge) { var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; return(editableGraphContainer.Connect(fromNode, fromRoute, toNode, toRoute, existingEdge).Cast <ScriptNodeConnection>()); }
private void m_gameDocumentRegistry_DocumentRemoved(object sender, ItemRemovedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; document.DirtyChanged -= m_document_DirtyChanged; document.UriChanged -= m_document_UriChanged; IGame game = document.Cast <IGame>(); if (document == m_designView.Context.Cast <IGameDocument>()) {// master document. IGrid grid = document.As <IGame>().Grid; GridRenderer gridRender = grid.Cast <GridRenderer>(); gridRender.DeleteVertexBuffer(); m_designView.Context = null; GameEngine.DestroyObject(game.Cast <NativeObjectAdapter>()); GameEngine.Clear(); } else {// sub document. DomNode masterNode = m_gameDocumentRegistry.MasterDocument.As <DomNode>(); DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>(); NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>(); gworld.Remove(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder")); } }
// an element is eligible to move into another container only it first moves out its current container private bool IsSelfContainedOrIntersected(DomNode element, DomNode container) { // the moving element should first move out of the parent container next to the common ancestor var commonAncestor = DomNode.GetLowestCommonAncestor(element, container); var currentContainer = element.Lineage.First(x => x.Parent == commonAncestor); if (element == currentContainer) { return(false); // no self containing } var control = m_viewingContext.Cast <AdaptableControl>(); var elemLocalBound = GetLocalBound(control, element.Cast <Element>()); var containerLocalBound = GetLocalBound(control, currentContainer.Cast <Element>()); containerLocalBound.Location = new PointF(0, GetTitleHeight(control)); containerLocalBound.Height -= GetLabelHeight(control);// exclude bottom label area elemLocalBound.Offset(GetSubContentOffset(control)); bool contained = containerLocalBound.Contains(elemLocalBound); containerLocalBound.Height -= GetTitleHeight(control);// no subcontent offset if element is moved out of the current container bool intersected = containerLocalBound.IntersectsWith(elemLocalBound); return(contained || intersected); }
/// <summary> /// Resize a container</summary> /// <param name="container">Container to resize</param> /// <param name="newWidth">New container width</param> /// <param name="newHeight">New container height</param> void IEditableGraphContainer <ScriptNode, ScriptNodeConnection, ICircuitPin> .Resize(object container, int newWidth, int newHeight) { var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; editableGraphContainer.Resize(container, newWidth, newHeight); }
private void m_gameDocumentRegistry_DocumentAdded(object sender, ItemInsertedEventArgs <IGameDocument> e) { IGameDocument document = e.Item; IGame game = document.Cast <IGame>(); if (document == m_gameDocumentRegistry.MasterDocument) { NativeObjectAdapter gameLevel = document.Cast <NativeObjectAdapter>(); GameEngine.CreateObject(gameLevel); GameEngine.SetGameLevel(gameLevel); gameLevel.UpdateNativeOjbect(); //create vertex buffer for grid. IGrid grid = document.As <IGame>().Grid; GridRenderer gridRender = grid.Cast <GridRenderer>(); gridRender.CreateVertices(); m_designView.Context = document.Cast <IGameContext>(); } DomNode masterNode = m_gameDocumentRegistry.MasterDocument.As <DomNode>(); DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>(); NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>(); gworld.Insert(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"), -1); }
/// <summary> /// Connects the "from" node/route to the "to" node/route by creating an IGraphEdge whose /// "from" node is "fromNode", "to" node is "toNode", etc.</summary> /// <param name="fromNode">"From" node</param> /// <param name="fromRoute">"From" edge route</param> /// <param name="toNode">"To" node</param> /// <param name="toRoute">"To" edge route</param> /// <param name="existingEdge">Existing edge that is being reconnected, or null if new edge</param> /// <returns>New edge connecting the "from" node/route to the "to" node/route</returns> public Connection Connect(Module fromNode, ICircuitPin fromRoute, Module toNode, ICircuitPin toRoute, Connection existingEdge) { var editableGraphContainer = DomNode.Cast <CircuitEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; return(editableGraphContainer.Connect(fromNode, fromRoute, toNode, toRoute, existingEdge).Cast <Connection>()); }
/// <summary>Gets whether the edge can be disconnected</summary> /// <param name="edge">Edge to disconnect</param> /// <returns>Whether the edge can be disconnected</returns> public bool CanDisconnect(Connection edge) { var editableGraphContainer = DomNode.Cast <CircuitEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; return(editableGraphContainer.CanDisconnect(edge)); }
/// <summary> /// Performs one-time initialization when this adapter's DomNode property is set. /// The DomNode property is only ever set once for the lifetime of this adapter.</summary> protected override void OnNodeSet() { base.OnNodeSet(); var editingContext = DomNode.Cast <EditingContext>(); editingContext.DirtyChanged += (sender, args) => Dirty = editingContext.Dirty; }
/// <summary> /// Finish MEF intialization for the component by creating DomNode tree for application data.</summary> void IInitializable.Initialize() { m_mainform.Shown += (sender, e) => { // create root node. var rootNode = new DomNode(Schema.gameType.Type, Schema.gameRootElement); rootNode.SetAttribute(Schema.gameType.nameAttribute, "Game"); // create Orc game object and add it to rootNode. var orc1 = CreateOrc("Orc1"); rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc1); // add a child Orc. var orcChildList = orc1.GetChildList(Schema.orcType.orcChild); orcChildList.Add(CreateOrc("Child Orc1")); var orc2 = CreateOrc("Orc2"); rootNode.GetChildList(Schema.gameType.gameObjectChild).Add(orc2); rootNode.InitializeExtensions(); // set active context and select orc object. m_contextRegistry.ActiveContext = rootNode; var selectionContext = rootNode.Cast <ISelectionContext>(); selectionContext.Set(new AdaptablePath <object>(orc1.GetPath())); }; }
/// <summary> /// Move the given nodes into the container</summary> /// <param name="newParent">New container</param> /// <param name="movingObjects">Nodes to move</param> void IEditableGraphContainer <ScriptNode, ScriptNodeConnection, ICircuitPin> .Move(object newParent, IEnumerable <object> movingObjects) { var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; editableGraphContainer.Move(newParent, movingObjects); }
private void RemoveNode(DomNode node) { if (node.Is <Group>()) { node.Cast <Group>().Changed -= GroupChanged; } }
protected override void OnNodeSet() { base.OnNodeSet(); // Only adapt to ICurve. if (!DomNode.Is <ICurve>()) { throw new InvalidOperationException("This adapter can only attach to instance of type that implements ICurve"); } DomNode.ChildInserting += (sender, e) => { var cp = e.Child.As <IControlPoint>(); if (cp != null) { // check curve limit. var curve = DomNode.Cast <ICurve>(); if (cp.X < curve.MinX || cp.X > curve.MaxX || cp.Y < curve.MinY || cp.Y > curve.MaxY) { throw new InvalidTransactionException("Cannot add control-point outside curve limits".Localize()); } } }; DomNode.AttributeChanged += (sender, e) => { try { // prevent re-entry if (m_validating) { return; } m_validating = true; var pt = e.DomNode.As <IControlPoint>(); var curve = pt == null ? null : pt.Parent; if (curve != null) { // keep x and y within curve limits. if (e.AttributeInfo.Equivalent(UISchema.controlPointType.xAttribute)) { pt.X = MathUtil.Clamp((float)e.NewValue, curve.MinX, curve.MaxX); } else if (e.AttributeInfo.Equivalent(UISchema.controlPointType.yAttribute)) { pt.Y = MathUtil.Clamp((float)e.NewValue, curve.MinY, curve.MaxY); } } } finally { m_validating = false; } }; }
/// <summary> /// Performs initialization when the adapter is connected to the viewing context's DomNode. /// Raises the Observer NodeSet event and performs custom processing.</summary> protected override void OnNodeSet() { // this adapter is registered on document and root statechart m_statechart = DomNode.Cast <Statechart>(); m_document = DomNode.Cast <Document>(); base.OnNodeSet(); }
/// <summary> /// Constructs descriptive name of circuit item. Debugging Helper method.</summary> /// <param name="domNode">DomNode of circuit item</param> /// <returns>Descriptive name of circuit item</returns> static public string GetDomNodeName(DomNode domNode) { string result = string.Empty; if (domNode.Is <Element>()) { result = domNode.Cast <Element>().Name; } else if (domNode.Is <GroupPin>()) { result = "Group Pin : " + domNode.Cast <GroupPin>().Name; } else if (domNode.Is <Wire>()) { var connection = domNode.Cast <Wire>(); int inputPinIndex, outputPinIndex; // during undo/redo, the pin index may temporarily out of range, need to check index before call OutputPin|InputPin if (connection.IsValid(out inputPinIndex, out outputPinIndex)) { result = "Edge from " + connection.OutputElement.Name + "[" + connection.OutputPin.Name + "]" + " to " + connection.InputElement.Name + "[" + connection.InputPin.Name + "]"; } else { result = "Edge from " + connection.OutputElement.Name + "[" + outputPinIndex + "]" + " to " + connection.InputElement.Name + "[" + inputPinIndex + "]"; } } else if (domNode.Is <Circuit>()) { var doc = domNode.As <IDocument>(); if (doc != null && doc.Uri != null) { result = "Circuit " + Path.GetFileNameWithoutExtension(doc.Uri.LocalPath); } else { result = "Circuit " + domNode.GetId(); } } if (result == string.Empty) { result = domNode.GetId() ?? domNode.ToString(); } return(result); }
// Scan for all sub-circuits that are referenced directly or indirectly by a module in // the root of the document public override void Write(DomNode root, Stream stream, Uri uri) { m_usedSubCircuits = new HashSet<Sce.Atf.Controls.Adaptable.Graphs.SubCircuit>(); foreach (var module in root.Cast<Circuit>().Elements) FindUsedSubCircuits(module.DomNode); base.Write(root, stream, uri); }
/// <summary> /// Unregisters the Control from the IContextRegistry and IControlHostService and disposes /// it and sets the circuitNode's ViewingContext's Control property to null.</summary> private void UnregisterControl(DomNode circuitNode, Control control) { //it's OK if the CircuitEditingContext was already removed or wasn't added to IContextRegistry. m_contextRegistry.RemoveContext(circuitNode.As <CircuitEditingContext>()); m_controlHostService.UnregisterControl(control); control.Visible = false; control.Dispose(); m_circuitNodeControls.Remove(circuitNode); circuitNode.Cast <ViewingContext>().Control = null; }
// Scan for all sub-circuits that are referenced directly or indirectly by a module in // the root of the document public override void Write(DomNode root, Stream stream, Uri uri) { #pragma warning disable 618 //mastered sub-circuits are obsolete m_usedSubCircuits = new HashSet<Sce.Atf.Controls.Adaptable.Graphs.SubCircuit>(); foreach (var module in root.Cast<Circuit>().Elements) FindUsedSubCircuits(module.DomNode); #pragma warning restore 618 base.Write(root, stream, uri); }
/// <summary> /// Gets item's display information</summary> /// <param name="item">Item being displayed</param> /// <param name="info">Item info, to fill out</param> public void GetInfo(object item, ItemInfo info) { DomNode node = item as DomNode; if (node != null) { if (node.Type == UISchema.UIRefType.Type) { info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefImage); string label = string.Empty; UIRef uiRef = node.As <UIRef>(); UIObject uiTarget = uiRef.UIObject; if (uiTarget != null) { label = uiTarget.Name; } info.Label = "[" + label + "]"; } else if (node.Is <Curve>()) { Curve cv = node.Cast <Curve>(); info.Label = string.IsNullOrWhiteSpace(cv.DisplayName) ? cv.Name : cv.DisplayName; info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.CurveImage); } else { NodeTypePaletteItem paletteItem = node.Type.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName); } info.Label = node.GetId(); } info.IsLeaf = !GetChildren(item).Any(); } else { EmptyRef emptyRef = item as EmptyRef; if (emptyRef != null) { info.Label = "Ref"; info.ImageIndex = info.GetImageList().Images.IndexOfKey(Resources.RefEmptyImage); info.IsLeaf = true; } } if (string.IsNullOrEmpty(info.Label)) { throw new ArgumentException("info.lable"); } }
/// <summary> /// Performs initialization when the adapter is connected to the group's DomNode. /// Raises the DomNodeAdapter NodeSet event and performs custom processing: /// creates a DomNodeListAdapter for various circuit elements.</summary> protected override void OnNodeSet() { m_modules = new DomNodeListAdapter <ScriptNode>(DomNode, groupType.moduleChild); m_connections = new DomNodeListAdapter <ScriptNodeConnection>(DomNode, groupType.connectionChild); new DomNodeListAdapter <ScriptAnnotation>(DomNode, groupType.annotationChild); new DomNodeListAdapter <ScriptGroupSocket>(DomNode, groupType.inputChild); new DomNodeListAdapter <ScriptGroupSocket>(DomNode, groupType.outputChild); m_thisModule = DomNode.Cast <ScriptNode>(); base.OnNodeSet(); }
/// <summary> /// Performs initialization when the adapter is connected to the group's DomNode. /// Raises the DomNodeAdapter NodeSet event and performs custom processing: /// creates a DomNodeListAdapter for various circuit elements.</summary> protected override void OnNodeSet() { m_modules = new DomNodeListAdapter <Module>(DomNode, Schema.groupType.moduleChild); m_connections = new DomNodeListAdapter <Connection>(DomNode, Schema.groupType.connectionChild); new DomNodeListAdapter <Annotation>(DomNode, Schema.groupType.annotationChild); new DomNodeListAdapter <GroupPin>(DomNode, Schema.groupType.inputChild); new DomNodeListAdapter <GroupPin>(DomNode, Schema.groupType.outputChild); m_thisModule = DomNode.Cast <Module>(); base.OnNodeSet(); }
/// <summary> /// Can given modules be moved into a new container</summary> /// <param name="newParent">New module parent</param> /// <param name="movingObjects">Objects being moved</param> /// <returns>True iff objects can be moved to new parent</returns> bool IEditableGraphContainer <ScriptNode, ScriptNodeConnection, ICircuitPin> .CanMove(object newParent, IEnumerable <object> movingObjects) { if (newParent.Is <IReference <ScriptNode> >()) { return(false); } var editableGraphContainer = DomNode.Cast <VisualScriptEditingContext>() as IEditableGraphContainer <Element, Wire, ICircuitPin>; return(editableGraphContainer.CanMove(newParent, movingObjects)); }
// Scan for all sub-circuits that are referenced directly or indirectly by a module in // the root of the document public override void Write(DomNode root, Stream stream, Uri uri) { #pragma warning disable 618 //mastered sub-circuits are obsolete m_usedSubCircuits = new HashSet <Sce.Atf.Controls.Adaptable.Graphs.SubCircuit>(); foreach (var module in root.Cast <Circuit>().Elements) { FindUsedSubCircuits(module.DomNode); } #pragma warning restore 618 base.Write(root, stream, uri); }
/// <summary> /// Gets the bounding rectangle of all circuit items in client coordinates</summary> /// <returns>Bounding rectangle of all circuit items in client coordinates</returns> public Rectangle GetBounds() { if (m_graph == null) { return(Rectangle.Empty); } IEnumerable <object> items = m_graph.Nodes; var annoDiagram = m_graph.As <IAnnotatedDiagram>(); if (annoDiagram != null) { items = items.Concat(annoDiagram.Annotations); } Rectangle bounds = GetBounds(items); if (DomNode.Is <Group>()) { // include group pins y range var group = DomNode.Cast <Group>(); int yMin = int.MaxValue; int yMax = int.MinValue; foreach (var pin in group.InputGroupPins.Concat(group.OutputGroupPins)) { var grpPin = pin.Cast <GroupPin>(); if (grpPin.Bounds.Y < yMin) { yMin = grpPin.Bounds.Y; } if (grpPin.Bounds.Y > yMax) { yMax = grpPin.Bounds.Y; } } // transform y range to client space if (yMin != int.MaxValue && yMax != int.MinValue) { var transformAdapter = m_control.Cast <ITransformAdapter>(); var minPt = Matrix3x2F.TransformPoint(transformAdapter.Transform, new PointF(0, yMin)); var maxPt = Matrix3x2F.TransformPoint(transformAdapter.Transform, new PointF(0, yMax)); yMin = (int)minPt.Y; yMax = (int)maxPt.Y; int width = bounds.Width; int height = yMax - yMin + 1; bounds = Rectangle.Union(bounds, new Rectangle(bounds.X, yMin, width, height)); } } return(bounds); }
/// <summary> /// Reads in the data for an EventSequenceDocument from the given stream</summary> /// <remarks>This method proves the concept that a document can be persisted in a custom /// file format that is not XML.</remarks> /// <param name="stream">Stream with event sequence data</param> /// <returns>A valid EventSequenceDocument if successful or null if the stream's data is invalid</returns> public static EventSequenceDocument Read(Stream stream) { using (StreamReader reader = new StreamReader(stream)) { string line = reader.ReadLine(); if (line != "eventSequence") { return(null); } DomNode root = new DomNode(DomTypes.eventSequenceType.Type, DomTypes.eventSequenceRootElement); bool readLineForEvent = true; while (true) { // The root has a sequence of children that are eventType nodes. if (readLineForEvent) { line = reader.ReadLine(); } if (string.IsNullOrEmpty(line)) { break; } readLineForEvent = true; DomNode eventNode; if (!ReadEvent(line, out eventNode)) { break; } root.GetChildList(DomTypes.eventSequenceType.eventChild).Add(eventNode); // Each eventType node may have zero or more resourceType nodes. while (true) { line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } DomNode resourceNode; if (!ReadResource(line, out resourceNode)) { // might be a line for an event readLineForEvent = false; break; } eventNode.GetChildList(DomTypes.eventType.resourceChild).Add(resourceNode); } } return(root.Cast <EventSequenceDocument>()); } }
public bool AddChild(object child) { bool added = false; ILayer layer = child.As<ILayer>(); if (layer != null) { if (!Layers.Contains(layer)) { Layers.Add(layer); added = true; } } else { IReference<IGameObject> reference = child.As<IReference<IGameObject>>(); if (reference != null) { if (reference.Target != null && !this.Contains(reference.Target) && !GameObjectReferences.Contains(reference)) { GameObjectReferences.Add(reference); added = true; } } else { IGameObject gameObject = child.As<IGameObject>(); if (gameObject != null && !this.Contains(gameObject)) { DomNode referenceNode = new DomNode(Schema.gameObjectReferenceType.Type); reference = referenceNode.Cast<IReference<IGameObject>>(); reference.Target = gameObject; GameObjectReferences.Add(reference); added = true; } } } return added; }
private void Init() { NativeObjectAdapter curLevel = GameEngine.GetGameLevel(); try { // create new document by creating a Dom node of the root type defined by the schema DomNode rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement); INameable nameable = rootNode.Cast<INameable>(); nameable.Name = "ThumbnailGenerator"; NativeObjectAdapter gameLevel = rootNode.Cast<NativeObjectAdapter>(); GameEngine.CreateObject(gameLevel); GameEngine.SetGameLevel(gameLevel); gameLevel.UpdateNativeOjbect(); NativeGameWorldAdapter gworld = rootNode.Cast<NativeGameWorldAdapter>(); m_game = rootNode.Cast<IGame>(); IGameObjectFolder rootFolder = m_game.RootGameObjectFolder; m_renderSurface = new TextureRenderSurface(96, 96); m_renderState = new RenderState(); m_renderState.RenderFlag = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit | GlobalRenderFlags.Shadows; } finally { GameEngine.SetGameLevel(curLevel); } m_mainWindow.Closed += delegate { GameEngine.DestroyObject(m_game.Cast<NativeObjectAdapter>()); m_renderSurface.Dispose(); m_renderState.Dispose(); }; }
public static Character New(ChildInfo childInfo) { DomNode node = new DomNode(Schema.characterType.Type, childInfo); return node.Cast<Character>(); }
private void Init() { if (m_game != null) return; NativeObjectAdapter curLevel = GameEngine.GetGameLevel(); try { // create new document by creating a Dom node of the root type defined by the schema DomNode rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement); INameable nameable = rootNode.As<INameable>(); nameable.Name = "Game"; NativeObjectAdapter gameLevel = rootNode.Cast<NativeObjectAdapter>(); GameEngine.CreateObject(gameLevel); GameEngine.SetGameLevel(gameLevel); gameLevel.UpdateNativeOjbect(); NativeGameWorldAdapter gworld = rootNode.Cast<NativeGameWorldAdapter>(); m_game = rootNode.Cast<IGame>(); IGameObjectFolder rootFolder = m_game.RootGameObjectFolder; m_renderSurface.Game = m_game; } finally { GameEngine.SetGameLevel(curLevel); } m_mainWindow.Closed += delegate { GameEngine.DestroyObject(m_game.Cast<NativeObjectAdapter>()); m_renderSurface.Dispose(); }; }
// Create circuit DOM hierarchy programmatically static public DomNode CreateTestCircuitProgrammatically(SchemaLoader schemaLoader) { var rootNode = new DomNode(Schema.circuitDocumentType.Type, Schema.circuitRootElement); // create an empty root prototype folder( required child by schema) rootNode.SetChild( Schema.circuitDocumentType.prototypeFolderChild, new DomNode(Schema.prototypeFolderType.Type)); var circuit = rootNode.Cast<Circuit>(); var inputFiles = new DomNode(Schema.groupType.Type).Cast<Group>(); inputFiles.Id = "groupInputFiles"; inputFiles.Name = "Input Files".Localize(); inputFiles.Bounds = new Rectangle(64, 96, 0, 0); // set node location, size will be auto-computed var firstWavgGroup = new DomNode(Schema.groupType.Type).Cast<Group>(); firstWavgGroup.Id = "first.Wav"; firstWavgGroup.Name = "first".Localize("as in, 'the first file'") + ".wav"; var buttonType = schemaLoader.GetNodeType(Schema.NS + ButtonTypeName); var button1 = new DomNode(buttonType).Cast<Module>(); button1.Id = "button1"; button1.Bounds = new Rectangle(0, 0, 0, 0); var button2 = new DomNode(buttonType).Cast<Module>(); button2.Bounds = new Rectangle(0, 64, 0, 0); button2.Id = "button2"; firstWavgGroup.Elements.Add(button1); firstWavgGroup.Elements.Add(button2); firstWavgGroup.Expanded = true; firstWavgGroup.Update(); var secondWavgGroup = new DomNode(Schema.groupType.Type).Cast<Group>(); secondWavgGroup.Id = "second.Wav"; secondWavgGroup.Name = "second".Localize("as in, 'the second file'") + ".wav"; var button3 = new DomNode(buttonType).Cast<Module>(); button3.Id = "button3"; button3.Bounds = new Rectangle(0, 0, 0, 0); var button4 = new DomNode(buttonType).Cast<Module>(); button4.Bounds = new Rectangle(0, 64, 0, 0); button4.Id = "button4"; secondWavgGroup.Elements.Add(button3); secondWavgGroup.Elements.Add(button4); secondWavgGroup.Expanded = true; secondWavgGroup.Update(); secondWavgGroup.Bounds = new Rectangle(0, 224, 0, 0); inputFiles.Elements.Add(firstWavgGroup); inputFiles.Elements.Add(secondWavgGroup); inputFiles.Update(); inputFiles.Expanded = true; circuit.Elements.Add(inputFiles); var structure = new DomNode(Schema.groupType.Type).Cast<Group>(); structure.Id = "structure".Localize("this is the name of a group of circuit elements; the name is arbitrary"); structure.Name = "structure".Localize("this is the name of a group of circuit elements; the name is arbitrary"); structure.Bounds = new Rectangle(352, 96, 0, 0); var subStream0 = new DomNode(Schema.groupType.Type).Cast<Group>(); subStream0.Id = "subStream0".Localize("this is the name of a group of circuit elements; the name is arbitrary"); subStream0.Name = "sub-stream 0".Localize("this is the name of a group of circuit elements; the name is arbitrary"); var lightType = schemaLoader.GetNodeType(Schema.NS + LightTypeName); var light1 = new DomNode(lightType).Cast<Module>(); light1.Id = "light1"; light1.Bounds = new Rectangle(0, 0, 0, 0); var light2 = new DomNode(lightType).Cast<Module>(); light2.Id = "light2"; light2.Bounds = new Rectangle(0, 64, 0, 0); var light3 = new DomNode(lightType).Cast<Module>(); light3.Id = "light3"; light3.Bounds = new Rectangle(0, 128, 0, 0); var light4 = new DomNode(lightType).Cast<Module>(); light4.Id = "light4"; light4.Bounds = new Rectangle(0, 192, 0, 0); var light5 = new DomNode(lightType).Cast<Module>(); light5.Id = "light5"; light5.Bounds = new Rectangle(0, 256, 0, 0); var light6 = new DomNode(lightType).Cast<Module>(); light6.Id = "light6"; light6.Bounds = new Rectangle(0, 320, 0, 0); subStream0.Elements.Add(light1); subStream0.Elements.Add(light2); subStream0.Elements.Add(light3); subStream0.Elements.Add(light4); subStream0.Elements.Add(light5); subStream0.Elements.Add(light6); subStream0.Expanded = true; subStream0.Update(); // this will generate group pins needed for edge connection structure.Elements.Add(subStream0); structure.Expanded = true; structure.Update(); circuit.Elements.Add(structure); // Note on 11/12/2013: adding wires currently crashes. Nested circuit groups aren't officially supported anyways. // make some edges betwen InputFiles & structure //var connection0 = CircuitAddEdge(inputFiles, 0, structure, 0); //circuit.Wires.Add(connection0); //var connection1 = CircuitAddEdge(inputFiles, 1, structure, 1); //circuit.Wires.Add(connection1); //var connection2 = CircuitAddEdge(inputFiles, 2, structure, 3); //circuit.Wires.Add(connection2); //var connection3 = CircuitAddEdge(inputFiles, 3, structure, 5); //circuit.Wires.Add(connection3); return rootNode; }
/// <summary> /// Projects the ghost</summary> private void ProjectGhost(DomNode ghost, Ray3F rayw, HitRecord? hit) { ITransformable xformnode = ghost.Cast<ITransformable>(); IBoundable bnode = ghost.As<IBoundable>(); AABB box = bnode.BoundingBox; Vec3F pt; if (hit.HasValue && hit.Value.hasNormal) { Vec3F rad = box.Radius; Vec3F norm = hit.Value.normal; Vec3F absNorm = Vec3F.Abs(norm); Vec3F offset = Vec3F.ZeroVector; if (absNorm.X > absNorm.Y) { if (absNorm.X > absNorm.Z) offset.X = norm.X > 0 ? rad.X : -rad.X; else offset.Z = norm.Z > 0 ? rad.Z : -rad.Z; } else { if (absNorm.Y > absNorm.Z) offset.Y = norm.Y > 0 ? rad.Y : -rad.Y; else offset.Z = norm.Z > 0 ? rad.Z : -rad.Z; } Vec3F localCenter = box.Center - xformnode.Translation; pt = hit.Value.hitPt + (offset - localCenter); } else { float offset = 6.0f * box.Radius.Length; pt = rayw.Origin + offset * rayw.Direction; } if (ViewType == ViewTypes.Front) pt.Z = 0.0f; else if (ViewType == ViewTypes.Top) pt.Y = 0.0f; else if (ViewType == ViewTypes.Left) pt.X = 0.0f; xformnode.Translation = pt; }
/// <summary> /// Unregisters the Control from the IContextRegistry and IControlHostService and disposes /// it and sets the circuitNode's ViewingContext's Control property to null.</summary> private void UnregisterControl(DomNode circuitNode, Control control) { //it's OK if the CircuitEditingContext was already removed or wasn't added to IContextRegistry. m_contextRegistry.RemoveContext(circuitNode.As<CircuitEditingContext>()); m_controlHostService.UnregisterControl(control); control.Visible = false; control.Dispose(); m_circuitNodeControls.Remove(circuitNode); circuitNode.Cast<ViewingContext>().Control = null; }
public static Settings New(ChildInfo childInfo) { DomNode node = new DomNode(Schema.settingsType.Type, childInfo); return node.Cast<Settings>(); }
/// <summary> /// Reads in the data for an EventSequenceDocument from the given stream</summary> /// <remarks>This method proves the concept that a document can be persisted in a custom /// file format that is not XML.</remarks> /// <param name="stream">Stream with event sequence data</param> /// <returns>A valid EventSequenceDocument if successful or null if the stream's data is invalid</returns> public static EventSequenceDocument Read(Stream stream) { using (StreamReader reader = new StreamReader(stream)) { string line = reader.ReadLine(); if (line != "eventSequence") return null; DomNode root = new DomNode(DomTypes.eventSequenceType.Type, DomTypes.eventSequenceRootElement); bool readLineForEvent = true; while (true) { // The root has a sequence of children that are eventType nodes. if (readLineForEvent) line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) break; readLineForEvent = true; DomNode eventNode; if (!ReadEvent(line, out eventNode)) break; root.GetChildList(DomTypes.eventSequenceType.eventChild).Add(eventNode); // Each eventType node may have zero or more resourceType nodes. while (true) { line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) break; DomNode resourceNode; if (!ReadResource(line, out resourceNode)) { // might be a line for an event readLineForEvent = false; break; } eventNode.GetChildList(DomTypes.eventType.resourceChild).Add(resourceNode); } } return root.Cast<EventSequenceDocument>(); } }