void GenerateRteCDataFunction(StreamWriter writer, ComponentDefenition compDef, CDataDefenition cdataDef) { String returnValue = cdataDef.DataTypeName + " "; String RteFuncName = RteFunctionsGenerator.GenerateFullCDataFunctionName(compDef, cdataDef); String fieldVariable = RteFunctionsGenerator.GenerateMultipleInstanceFunctionArguments(compDef.MultipleInstantiation); writer.WriteLine(returnValue + RteFuncName + fieldVariable); writer.WriteLine("{"); if (!compDef.MultipleInstantiation) //single instantiation component { ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); if (components.Count > 0) { /* At least one component exists at this step */ ComponentInstance compInstance = components[0]; String compName = RteFunctionsGenerator.GenerateComponentName(compInstance.Name); String field = RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(compDef, cdataDef); writer.WriteLine(" return " + compName + "." + field + ";"); } } else //multiple instantiation component { String field = RteFunctionsGenerator.GenerateRteCDataFieldInComponentDefenitionStruct(compDef, cdataDef); writer.WriteLine(" return ((" + compDef.Name + "*)instance)->" + field + ";"); } writer.WriteLine("}"); writer.WriteLine(""); }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (!CheckMIDI(zComponentInstance)) { return; } base.PlayInternal(zComponentInstance, target, curve, dontPlayComponents: true); if (_switchComponentSwitchType == SwitchComponentSwitchType.OnPlay && _defferedSelectedComponent != null) { _selectedComponent = _defferedSelectedComponent; _defferedSelectedComponent = null; } if (_useGlobalSwitch && _globalSwitch != null) { GlobalSwitch globalSwitch = EventManager.Instance._globalParameterManager._globalSwitches.FindItem(_globalSwitch); if (globalSwitch != null) { GlobalSwitchContainer globalSwitchContainer = GetGlobalSwitchContainer(globalSwitch.GetActiveSwitch()); if (globalSwitchContainer != null) { _selectedComponent = globalSwitchContainer._components[0]; } } } if (_selectedComponent != null) { if (_activeMusicTimeSettings != null && IsMusicSyncEnabled() && _syncToMusicOnFirstPlay && !_musicTimeResetOnPlay) { _componentInstance._instance.SetPlayScheduledAdditive(_activeMusicTimeSettings.GetDelay(this), 0.0); } _selectedComponent.PlayInternal(zComponentInstance, 0f, 0.5f); } }
public void SetUp() { var atom = new Atom( "atom", new[] { new Property("property-name", "property-type", new InheritedPropertyValue("property-alias")) }); var containerSpecification = new ContainerSpecification("container"); var container = containerSpecification.Create(); container.Insert(0, atom); var widgetSpecification = new WidgetSpecification( "widget", new[] { new PropertySpecification("property-alias", "property-type", string.Empty) }, new[] { container }); var buildContext = new BuildData(Enumerable.Empty<IContextItem>()); var widget = widgetSpecification.Create(); widget.FindOrCreateProperty(new PropertySpecification("property-alias", "property-type", string.Empty)); widget.Properties.Single().Value = new FixedPropertyValue("property-value"); var builder = new Builder(RenderingInstructions.BuildForPreview(), w => widgetSpecification, null); this.instance = widget.Build(builder, new[] { 0 }, buildContext); }
public static ComponentInstance[][] CreateNewInstanceArray(Entity selectedEntity) { var instancesDB = selectedEntity.GetDataBlob <ComponentInstancesDB>(); if (instancesDB == null) { return(new ComponentInstance[0][]); } var componentsDict = instancesDB.ComponentsByDesign; var instancesArray = new ComponentInstance[componentsDict.Count][]; int i = 0; foreach (var desgnsLists in componentsDict.Values) { instancesArray[i] = new ComponentInstance[desgnsLists.Count]; for (int j = 0; j < desgnsLists.Count; j++) { instancesArray[i][j] = desgnsLists[j]; } i++; } return(instancesArray); }
public void SetUp() { var atom = new Atom( "atom", new[] { new Property("property-name", "property-type", new InheritedPropertyValue("property-alias")) }); var containerSpecification = new ContainerSpecification("container"); var container = containerSpecification.Create(); container.Insert(0, atom); var widgetSpecification = new WidgetSpecification( "widget", new[] { new PropertySpecification("property-alias", "property-type", string.Empty) }, new[] { container }); var buildContext = new BuildData(Enumerable.Empty <IContextItem>()); var widget = widgetSpecification.Create(); widget.FindOrCreateProperty(new PropertySpecification("property-alias", "property-type", string.Empty)); widget.Properties.Single().Value = new FixedPropertyValue("property-value"); var builder = new Builder(RenderingInstructions.BuildForPreview(), w => widgetSpecification, null); this.instance = widget.Build(builder, new[] { 0 }, buildContext); }
private void PlayRandomomponent(ComponentInstance zComponentInstance) { if (_playMode == RandomComponentPlayMode.Random) { int num = _shuffleBag.get(); _selectedAudioClip = _audioClips[num]; } else { int num2 = -1; if (!_shareRandomNoRepeatHistory) { num2 = GetNextRandomNoRepeatIndex(); } else { RandomAudioClipComponent randomAudioClipComponent = base.ComponentHolder as RandomAudioClipComponent; if ((bool)randomAudioClipComponent) { num2 = randomAudioClipComponent.GetNextRandomNoRepeatIndex(); } } if (num2 < 0) { return; } _selectedAudioClip = _audioClips[num2]; } if (_selectedAudioClip != null) { base.AudioClip = _selectedAudioClip; base.PlayInternal(zComponentInstance, 0f, 0.5f, dontPlayComponents: false); } }
public void GestureComplete(IPointerEvent evnt) { ComponentInstance toMove = moving; if (toMove != null) { moving = null; layoutCanvas.Execute((ILayoutAccess lo) => { Component comp = toMove.Component; List <Location> toCheck = new List <Location>(); foreach (ConnectionPoint conn in comp.Connections) { toCheck.Add(movingLocation.Translate(conn.Dx, conn.Dy)); } if (curValid) { lo.MoveComponent(toMove.Component, curDx, curDy); layoutCanvas.WiringPoints.Update(); WireTools.CheckForMerges(lo, layoutCanvas.WiringPoints, toCheck); layoutCanvas.WiringPoints.Update(); WireTools.CheckForSplits(lo, layoutCanvas.WiringPoints, new Component[] { comp }); } else { lo.RemoveComponent(toMove.Component); layoutCanvas.WiringPoints.Update(); WireTools.CheckForMerges(lo, layoutCanvas.WiringPoints, toCheck); } }); layoutCanvas.Hidden = null; layoutCanvas.Gesture = null; evnt.RepaintCanvas(); } }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (CheckMIDI(zComponentInstance)) { if (!IsPlaying() && _resetOnFirstPlay) { _playingComponentIndex = 0; _prevPlayingComponentIndex = 0; } if (!_syncAdvanceBetweenInstances && _sequenceAdvanceMode != 0) { _playingComponentIndex = 0; } _onlyStopOnce = true; _advanceEventTriggered = false; _stopInProgress = false; base.PlayInternal(zComponentInstance, _fadeInTime, _fadeInCurve, dontPlayComponents: true); double playScheduledDelay = (double)_transitionOffset + base._random.NextDouble() * (double)_transitionOffsetRandomization; double playScheduled = 0.0; if (_activeMusicTimeSettings != null && IsMusicSyncEnabled() && _syncToMusicOnFirstPlay && !_musicTimeResetOnPlay) { playScheduled = _activeMusicTimeSettings.GetDelay(this); } _componentInstance._instance.SetPlayScheduledAdditive(playScheduled, playScheduledDelay); PlayNextEntry(); } }
public void GestureCancel(IPointerEvent evnt) { moving = null; curValid = false; layoutCanvas.Hidden = null; evnt.RepaintCanvas(); }
public static String LinkToTheComponentInstance(ComponentInstance compInstance) { String compName = GenerateComponentName(compInstance.Name); String result = "(" + RteFunctionsGenerator.ComponentInstancePointerDatatype + ")&" + compName; return(result); }
// Instantiate a component of a given type, name and config in the scene. public bool AddComponent(string type, string name, string path, Orrb.RendererComponentConfig config, bool enabled) { if (components_dictionary_.ContainsKey(name)) { Logger.Error("ComponentManager::AddComponent::Component already exists: {0}.", name); return(false); } ComponentInstance component_instance = InstantiateComponentByType(type, name, path, enabled); if (component_instance == null) { Logger.Error("ComponentManager::AddComponent::Failed to instantiate component: {0} ({1}).", name, type); return(false); } if (!component_instance.renderer_component.InitializeComponent(config)) { Logger.Error("ComponentManager::AddComponent::Failed to initialize: {0} of type: {1}.", name, type); return(false); } components_.Add(component_instance); components_dictionary_.Add(name, component_instance); return(true); }
private void PlayRandomomponent(ComponentInstance zComponentInstance) { if (_playMode == RandomComponentPlayMode.Random) { int index = _shuffleBag.get(); _selectedComponent = _components[index]; } else { int num = -1; if (!_shareRandomNoRepeatHistory) { num = GetNextRandomNoRepeatIndex(); } else { RandomComponent randomComponent = base.ComponentHolder as RandomComponent; if ((bool)randomComponent) { num = randomComponent.GetNextRandomNoRepeatIndex(); } } if (num < 0) { return; } _selectedComponent = _components[num]; } if (_selectedComponent != null) { _selectedComponent.PlayInternal(zComponentInstance, 0f, 0.5f); } }
public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance) { if (!componentInstance.HasAblity <WeaponState>()) { var wpnState = new WeaponState(); wpnState.WeaponType = "Missile Launcher"; wpnState.WeaponStats = new (string name, double value, ValueTypeStruct valueType)[3];
void GenerateRteWritePortFieldFunction(StreamWriter writer, ComponentDefenition compDef, PortDefenition port, SenderReceiverInterfaceField field) { String returnValue = Properties.Resources.STD_RETURN_TYPE; String RteFuncName = RteFunctionsGenerator.GenerateReadWriteConnectionFunctionName(port, field); String fieldVariable = RteFunctionsGenerator.GenerateSenderReceiverInterfaceArguments(field, port.PortType, compDef.MultipleInstantiation); writer.WriteLine(returnValue + RteFuncName + fieldVariable); writer.WriteLine("{"); if (!compDef.MultipleInstantiation) //single instantiation component { ComponentInstancesList components = AutosarApplication.GetInstance().GetComponentInstanceByDefenition(compDef); if (components.Count > 0) { ComponentInstance compInstance = components[0]; String compName = RteFunctionsGenerator.GenerateComponentName(compInstance.Name); String fieldName = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(port, field); writer.WriteLine(" " + compName + "." + fieldName + " = *" + field.Name + ";"); } } else //multiple instantiation component { String rteStructFieldName = RteFunctionsGenerator.GenerateRteWriteFieldInComponentDefenitionStruct(port, field); String instanceLine = "((" + compDef.Name + "*)instance)->" + rteStructFieldName + " = *" + field.Name + ";"; writer.WriteLine(" " + instanceLine); } writer.WriteLine(" return " + Properties.Resources.RTE_E_OK + ";"); writer.WriteLine("}"); writer.WriteLine(""); //} }
public void OnConstructionComplete(Entity industryEntity, CargoStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo) { var colonyConstruction = industryEntity.GetDataBlob <IndustryAbilityDB>(); batchJob.NumberCompleted++; batchJob.ResourcesRequired = designInfo.ResourceCosts; batchJob.ProductionPointsLeft = designInfo.IndustryPointCosts; if (batchJob.InstallOn != null) { ComponentInstance specificComponent = new ComponentInstance((ComponentDesign)designInfo); if (batchJob.InstallOn == industryEntity || StorageSpaceProcessor.HasEntity(storage, batchJob.InstallOn.GetDataBlob <CargoAbleTypeDB>())) { EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent); ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn); } } else { StorageSpaceProcessor.AddCargo(storage, (ComponentDesign)designInfo, 1); } if (batchJob.NumberCompleted == batchJob.NumberOrdered) { colonyConstruction.ProductionLines[productionLine].Jobs.Remove(batchJob); if (batchJob.Auto) { colonyConstruction.ProductionLines[productionLine].Jobs.Add(batchJob); } } }
public void SetUp() { var atom = new Atom( "atom", new[] { new Property("property-name", "property-type", new InheritedPropertyValue("property-name")) }); var parentSpecification = new ContainerSpecification("parent-container"); var grandparentSpecification = new ContainerSpecification("grandparent-container"); grandparentSpecification.AddProperty(new PropertySpecification("property-name", "property-type", string.Empty)); var buildContext = new BuildData(Enumerable.Empty <IContextItem>()); var parent = parentSpecification.Create(); parent.Insert(0, atom); var grandparent = grandparentSpecification.Create(); grandparent.FindOrCreateProperty(new PropertySpecification("property-name", "property-type", string.Empty)); grandparent.Properties.Single().Value = new FixedPropertyValue("property-value"); grandparent.Insert(0, parent); var builder = new Builder(RenderingInstructions.BuildForPreview(), null, null); this.instance = grandparent.Build(builder, new[] { 0 }, buildContext); }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (CheckMIDI(zComponentInstance)) { ResetParameters(); base.PlayInternal(zComponentInstance, _fadeInTime, _fadeInCurve, dontPlayComponents); } }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents = false) { if (CheckMIDI(zComponentInstance)) { finishedPlayingOncePerFrame = false; base.PlayInternal(zComponentInstance, target, curve, dontPlayComponents); } }
public void GestureCancel(IPointerEvent evnt) { Send(PokeEventType.PokeCancel, evnt); if (layoutModel.Gesture == this) { layoutModel.Gesture = null; } poking = null; }
public ComponentInstance CreateComponent(ComponentDefenition componentDefenition, double X, double Y) { int leftPortCount = 0; int rightPortCount = 0; foreach (PortDefenition portDef in componentDefenition.Ports) { if ((portDef.PortType == PortType.Receiver) || (portDef.PortType == PortType.Server)) { leftPortCount++; } else { rightPortCount++; } } double componentHeight = Math.Max(leftPortCount, rightPortCount) * 50 + 60; ComponentInstance componentInstance = new ComponentInstance(); componentInstance.Name = GetComponentName(componentDefenition); componentInstance.ComponentDefenitionGuid = componentDefenition.GUID; componentInstance.Painter.Left = X - 60; componentInstance.Painter.Right = X + 60; componentInstance.Painter.Top = Y - componentHeight / 2.0; componentInstance.Painter.Height = componentHeight; componentInstance.UpdatePims(); double LeftTop = componentInstance.Painter.Top + 30; double RightTop = LeftTop; double LeftPos = componentInstance.Painter.Left - 10; double RightPos = componentInstance.Painter.Right - 10; /* Create all port painters from defenition */ foreach (PortDefenition portDef in componentDefenition.Ports) { PortPainter newPort; if ((portDef.PortType == PortType.Receiver) || (portDef.PortType == PortType.Server)) { newPort = CreatePortPainter(portDef, LeftPos, LeftTop); newPort.ConnectionPortLocation = RectangleSide.Left; LeftTop += 50; } else { newPort = CreatePortPainter(portDef, RightPos, RightTop); newPort.ConnectionPortLocation = RectangleSide.Right; RightTop += 50; } componentInstance.Ports.Add(newPort); } componentInstance.UpdateCData(); componentInstance.UpdatePims(); return(componentInstance); }
public void GestureStart(IPointerEvent evnt) { bool accepted = Send(PokeEventType.PokeStart, evnt); if (!accepted) { poking = null; new GestureNull(layoutModel).GestureStartWithoutPoke(evnt); } }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (CheckMIDI(zComponentInstance)) { base.PlayInternal(zComponentInstance, _fadeInTime, _fadeInCurve, dontPlayComponents: true); _waitToStop = false; PlayStage(Stage.Intro); PlayStage(Stage.Loop); } }
public void MapInput(string inputColumnName, TermLookup.InputColumnUsageType inputColumnUsageType) { this.SetInputUsageType(inputColumnName, DTSUsageType.UT_READONLY); ComponentInstance.SetInputColumnProperty( Component.InputCollection[0].ID, Component.InputCollection[0].InputColumnCollection[inputColumnName].ID, "InputColumnType", (int)inputColumnUsageType ); }
public GesturePoke(LayoutCanvasModel layoutModel, ComponentInstance poking) { this.layoutModel = layoutModel; this.poking = poking; Transaction xn = new Transaction(); ILayoutAccess layout = xn.RequestReadAccess(layoutModel.Layout); using (xn.Start()) { pokingLocation = poking.Component.GetLocation(layout); } }
public void Paint(IPaintbrush pb) { ComponentInstance cur = poking; if (cur != null) { Location loc = pokingLocation; pb.TranslateCoordinates(loc.X, loc.Y); Pokeable dest = cur.Component as Pokeable; dest.PaintPokeProgress(new ComponentPainter(pb, new DummyInstanceState(cur))); } }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (CheckMIDI(zComponentInstance)) { if (_delayOnFirstPlay) { float num = _loopDelay + UnityEngine.Random.Range(_delayRandomization, _delayMaxRandomization); zComponentInstance._instance.SetPlayScheduledAdditive(num, 0.0); } PlayRandomomponent(zComponentInstance); } }
public virtual void SetInputUsageType(IDTSVirtualInput90 vi, IDTSVirtualInputColumn90 vcol, DTSUsageType usageType, bool forceOverwrite) { // This will not make a DT_READWRITE column more restrctive :) Only less restrictive if (vcol.UsageType != DTSUsageType.UT_READWRITE || forceOverwrite) { ComponentInstance.SetUsageType( Component.InputCollection[0].ID, vi, vcol.LineageID, usageType ); } }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (CheckMIDI(zComponentInstance)) { if (_dialogAudioLoadedFrom == DialogAudioLoadedFrom.CustomAudioClipLoader && FabricManager.Instance._customAudioClipLoader != null) { StartCoroutine(LoadPlayCoroutine(zComponentInstance, target, curve, dontPlayComponents)); return; } Load(); base.PlayInternal(zComponentInstance, target, curve, dontPlayComponents); } }
public GestureTranslate(LayoutCanvasModel layoutCanvas, ComponentInstance moving) { this.layoutCanvas = layoutCanvas; this.moving = moving; Transaction xn = new Transaction(); ILayoutAccess layout = xn.RequestReadAccess(layoutCanvas.Layout); using (xn.Start()) { this.movingLocation = moving.Component.GetLocation(layout); } }
private IGesture GetGesture(IPointerEvent evnt, bool considerPoke) { if (layoutCanvas.WiringPoints == null) { return(null); } Location eLoc = new Location(evnt.X, evnt.Y); Location snapLoc = Constants.SnapToGrid(eLoc); if (layoutCanvas.WiringPoints.Contains(snapLoc)) { int d2 = eLoc.GetDistance2(snapLoc); if (d2 < 16 * 16) { return(new GestureWire(layoutCanvas, snapLoc)); } } Instance found = null; Transaction xn = new Transaction(); ILayoutAccess lo = xn.RequestReadAccess(layoutCanvas.Layout); using (xn.Start()) { foreach (Component component in lo.Components) { Location iloc = component.GetLocation(lo); if (component.Contains(eLoc.X - iloc.X, eLoc.Y - iloc.Y)) { found = layoutCanvas.LayoutSim.GetInstance(lo, component); } } } ComponentInstance foundComp = found as ComponentInstance; if (foundComp != null) { if (considerPoke && foundComp.Component is Pokeable) { return(new GesturePoke(layoutCanvas, foundComp)); } else { return(new GestureTranslate(layoutCanvas, foundComp)); } } else { return(new GesturePan(layoutCanvas)); } }
public override void PlayInternal(ComponentInstance zComponentInstance, float target, float curve, bool dontPlayComponents) { if (CheckMIDI(zComponentInstance)) { double offset = 0.0; if (_activeMusicTimeSettings != null) { offset = _activeMusicTimeSettings.GetDelay(); midiSequencer.SetTempo((uint)_activeMusicTimeSettings._bpm); midiSequencer.Looping = _loop; } midiSequencer.Play(offset); base.PlayInternal(zComponentInstance, _fadeInTime, _fadeInCurve, dontPlayComponents: true); } }
public void SetUp() { var atom = new Atom( "atom", new[] { new Property("property-name", "property-type", new InheritedPropertyValue("property-name")) }); var parentSpecification = new ContainerSpecification("parent-container"); var grandparentSpecification = new ContainerSpecification("grandparent-container"); grandparentSpecification.AddProperty(new PropertySpecification("property-name", "property-type", string.Empty)); var buildContext = new BuildData(Enumerable.Empty<IContextItem>()); var parent = parentSpecification.Create(); parent.Insert(0, atom); var grandparent = grandparentSpecification.Create(); grandparent.FindOrCreateProperty(new PropertySpecification("property-name", "property-type", string.Empty)); grandparent.Properties.Single().Value = new FixedPropertyValue("property-value"); grandparent.Insert(0, parent); var builder = new Builder(RenderingInstructions.BuildForPreview(), null, null); this.instance = grandparent.Build(builder, new[] { 0 }, buildContext); }
public ComponentInstanceMarshalled(ComponentInstance component) { this.deleg = component; }
/// <summary> /// Adds TestComponent and instance to test-bench. Populates all mapping related to the TestComponent. /// </summary> /// <param name="testComponent">CyPhy TestComponent.</param> /// <param name="modelicaModel">CyPhy ModelicaModel of the testComponent.</param> private void AddTestComponent(CyPhy.TestComponent testComponent, CyPhy.ModelicaModel modelicaModel) { Modelica.Component testComponent_mo = null; // META-1624 : TestComponents in the test-bench are all seen as self-contained models // and will be generated as they appear there inside the Modelica package-tree. testComponent_mo = new Component(testComponent) { FullName = MainPackage + ".TestComponents." + testComponent.Name, Extends = modelicaModel.Attributes.Class, }; // Add all defined Parameters at the component-level foreach (var cyPhyParameter in testComponent.Children.ParameterCollection) { var parameter_mo = new UnitParameter() { Name = CodeGenerator.ParameterPrefix + cyPhyParameter.Name, Value = this.GetParameterModelicaValue(cyPhyParameter), Modifier = this.GetParameterModifier(cyPhyParameter) }; testComponent_mo.CyPhyParameters.Add(parameter_mo); } // Add all modelicaParameters from the ModelicaModel. foreach (var parameter in modelicaModel.Children.ModelicaParameterCollection) { var value = this.GetModelicaParameterValue(parameter); if (string.IsNullOrWhiteSpace(value) == false) { testComponent_mo.Parameters.Add( new UnitParameter() { Name = parameter.Name, Value = new ModelicaValue(value) }); } } // Add all modelicaRedeclares from the ModelicaModel. foreach (var redeclareParameter in modelicaModel.Children.ModelicaRedeclareCollection) { var value = redeclareParameter.Attributes.Value; if (string.IsNullOrWhiteSpace(value) == false) { testComponent_mo.Parameters.Add( new UnitRedeclareParameter(redeclareParameter) { Value = new ModelicaValue(value) }); } } this.testBench_mo.TestComponents.Add(testComponent_mo); // Make sure there are margins to the upper- and left-border int canvasX = testComponent.GenericAspect.X > ScaleFactor * ComponentIconSize ? testComponent.GenericAspect.X : ScaleFactor * ComponentIconSize; int canvasY = testComponent.GenericAspect.Y > ScaleFactor * ComponentIconSize ? testComponent.GenericAspect.Y : ScaleFactor * ComponentIconSize; // Make sure there are margins to the bottom- and right-border this.testBench_mo.CanvasXMax = canvasX + (ScaleFactor * ComponentIconSize) > this.testBench_mo.CanvasXMax ? canvasX + (ScaleFactor * ComponentIconSize) : this.testBench_mo.CanvasXMax; this.testBench_mo.CanvasYMax = canvasY + (ScaleFactor * ComponentIconSize) > this.testBench_mo.CanvasYMax ? canvasY + (ScaleFactor * ComponentIconSize) : this.testBench_mo.CanvasYMax; var testComponentInstance_mo = new ComponentInstance(testComponent) { InstanceOf = testComponent_mo, CanvasX = canvasX, CanvasY = canvasY }; var testComponentInfo = new ComponentInfo(testComponent.Impl as GME.MGA.IMgaFCO, "ContextModel", this.traceability); this.instanceURIMap.Add(string.Format("{0}.TestBenches.{1}.{2}", MainPackage, this.testBench_mo.Name, testComponent.Name), testComponentInfo); var uri = MainPackage + ".TestComponents." + testComponent.Name; if (this.modelURIMap.ContainsKey(uri) == false) { this.modelURIMap.Add(uri, testComponentInfo); } if (this.extendsURIMap.ContainsKey(testComponent_mo.Extends) == false) { var testComponentExtendInfo = new ComponentInfo(modelicaModel.Impl as GME.MGA.IMgaFCO, "ContextModel", this.traceability); this.extendsURIMap.Add(testComponent_mo.Extends, testComponentExtendInfo); } // Parameters of instance foreach (var parameter in testComponent.Children.ParameterCollection) { var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault(); if (vf != null && vf.ParentContainer.ID == this.testBench_mo.Impl.ID) { var parameter_mo = this.GetArgumentParameter(this.testBench_mo.Impl.ID, parameter, vf); testComponentInstance_mo.Parameters.Add(parameter_mo); } } this.testBench_mo.TestComponentInstances.Add(testComponentInstance_mo); // ModelicaConnectors foreach (var port in testComponent.Children.ModelicaConnectorCollection) { foreach (var dstPort in port.DstConnections.PortCompositionCollection .Select(c => c.DstEnds.ModelicaConnector) .Where(p => p.ParentContainer is CyPhy.ModelicaModel == false)) { CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPort(port); if (srcConnector == null) { continue; } CyPhy.ModelicaConnector dstConnector = null; if (dstPort.ParentContainer is CyPhy.TestComponent) { dstConnector = this.GetModelicaModelConnectorFromComponentPort(dstPort); } else if (dstPort.ParentContainer is CyPhy.ComponentAssembly) { dstConnector = dstPort; } else if (dstPort.ParentContainer is CyPhy.Environment) { dstConnector = dstPort; } // The Fidelty Selected might not have this Connection - don't make it. // Or it might be a floating connector with no purpose. if (dstConnector == null) { continue; } var connection_mo = new Connection(srcConnector.Name, dstConnector.Name) { SrcInstanceName = testComponent.Name, DstInstanceName = dstPort.ParentContainer.Name, Type = srcConnector.Attributes.Class }; this.testBench_mo.Connections.Add(connection_mo); } } // Connectors - aka portContainers foreach (var portContainer in testComponent.Children.ConnectorCollection) { if (portContainer.Children.ModelicaConnectorCollection.Count() != 1) { continue; } foreach (var dstPortContainer in portContainer.DstConnections.ConnectorCompositionCollection.Select(c => c.DstEnds.Connector)) { if (dstPortContainer.Children.ModelicaConnectorCollection.Count() != 1) { continue; } CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPortContainer(portContainer); if (srcConnector == null) { continue; } CyPhy.ModelicaConnector dstConnector = null; string dstConnectorName = "ERROR No Name Assigned"; if (dstPortContainer.ParentContainer is CyPhy.TestComponent) { dstConnector = this.GetModelicaModelConnectorFromComponentPortContainer(dstPortContainer); dstConnectorName = dstConnector.Name; } else if (dstPortContainer.ParentContainer is CyPhy.ComponentAssembly) { dstConnector = dstPortContainer.Children.ModelicaConnectorCollection.FirstOrDefault(); dstConnectorName = dstPortContainer.Name.Replace(' ', '_'); } else if (dstPortContainer.ParentContainer is CyPhy.Environment) { this.Logger.WriteDebug("Environment connected in Connector-chains not supported!"); continue; } // The Fidelty Selected might not have this Connection - don't make it. // Or it might be a floating connector with no purpose. if (dstConnector == null) { continue; } var connection_mo = new Connection(srcConnector.Name, dstConnectorName) { SrcInstanceName = testComponent.Name, DstInstanceName = dstPortContainer.ParentContainer.Name, Type = srcConnector.Attributes.Class }; this.testBench_mo.Connections.Add(connection_mo); } } }
/// <summary> /// Adds the component to componentAssembly_mo as an instance. /// </summary> /// <param name="componentAssembly_mo">ComponentAssembly that contains the component.</param> /// <param name="parentComponentAssembly_mo">ComponentAssembly that contains componentAssembly_mo.</param> /// <param name="component">CyPhy Component to add.</param> private void AddComponent(ComponentAssembly componentAssembly_mo, ComponentAssembly parentComponentAssembly_mo, CyPhy.Component component) { var ca = componentAssembly_mo.Impl; var modelicaModel = this.GetModelicaModelFromComponent(component); // Make sure there are margins to the top- and left-border int canvasX = component.GenericAspect.X > ScaleFactor * ComponentIconSize ? component.GenericAspect.X : ScaleFactor * ComponentIconSize; int canvasY = component.GenericAspect.Y > ScaleFactor * ComponentIconSize ? component.GenericAspect.Y : ScaleFactor * ComponentIconSize; // Make sure there are margins to the bottom- and right-border componentAssembly_mo.CanvasXMax = canvasX + (ScaleFactor * ComponentIconSize) > componentAssembly_mo.CanvasXMax ? canvasX + (ScaleFactor * ComponentIconSize) : componentAssembly_mo.CanvasXMax; componentAssembly_mo.CanvasYMax = canvasY + (ScaleFactor * ComponentIconSize) > componentAssembly_mo.CanvasYMax ? canvasY + (ScaleFactor * ComponentIconSize) : componentAssembly_mo.CanvasYMax; var componentInstance_mo = new ComponentInstance(component) { InstanceOf = this.treeComponents[component.DerivedFrom().ID], CanvasX = canvasX, CanvasY = canvasY }; foreach (var parameter in component.Children.ParameterCollection) { // META-3622 if (String.IsNullOrWhiteSpace(parameter.Attributes.Dimension) || parameter.Attributes.Dimension.Trim() == "1") { var vf = parameter.SrcConnections.ValueFlowCollection.FirstOrDefault(); if (vf != null && vf.ParentContainer.ID == ca.ID) { var parameter_mo = this.GetArgumentParameter(ca.ID, parameter, vf); componentInstance_mo.Parameters.Add(parameter_mo); } } } // META-2189 Overwrite ModelicaParameters connected to properties with formulated values in the design. foreach (var modelicaParameter in modelicaModel.Children.ModelicaParameterCollection) { var connection = modelicaParameter.SrcConnections.ModelicaParameterPortMapCollection.FirstOrDefault(); if (connection != null && connection.SrcEnds.Property != null) { double temp; var value = modelicaParameter.Attributes.Value.Trim(); if (double.TryParse(modelicaParameter.Attributes.Value, out temp) || value == "true" || value == "false" || (value.StartsWith("\"") && value.EndsWith("\""))) { var parameter_mo = new UnitParameter(); parameter_mo.Name = modelicaParameter.Name; parameter_mo.Value = new ModelicaValue(modelicaParameter.Attributes.Value.Trim()); componentInstance_mo.Parameters.Add(parameter_mo); } } } componentAssembly_mo.ComponentInstances.Add(componentInstance_mo); string componentModelicaURI = componentAssembly_mo.Name + "." + componentInstance_mo.Name; var parentCA = parentComponentAssembly_mo; while (parentCA != null) { componentModelicaURI = parentCA.Name + "." + componentModelicaURI; parentCA = parentCA.ParentComponentAssembly; } this.ExtractPCCInputs(component, componentModelicaURI); string modelType; if (modelicaModel is CyPhy.CyberModel) { modelType = "ControllerModel"; } else { modelType = "PlantModel"; } var componentInfo = new ComponentInfo(component.Impl as GME.MGA.IMgaFCO, modelType, this.traceability); this.instanceURIMap.Add(string.Format("{0}.TestBenches.{1}.{2}", MainPackage, this.testBench_mo.Name, componentModelicaURI), componentInfo); if (this.modelURIMap.ContainsKey(componentInstance_mo.InstanceOf.FullName) == false) { this.modelURIMap.Add(componentInstance_mo.InstanceOf.FullName, componentInfo); } if (this.extendsURIMap.ContainsKey(componentInstance_mo.InstanceOf.Extends) == false) { var componentExtendInfo = new ComponentInfo(modelicaModel.Impl as GME.MGA.IMgaFCO, modelType, this.traceability); this.extendsURIMap.Add(componentInstance_mo.InstanceOf.Extends, componentExtendInfo); } // Iterate over all ports and look for connections FROM the port. These connections will generate equations in the // component assembly if the connections is not entering a ModelicaModel. // Connections from ModelicaConnectors (Components) foreach (var port in component.Children.ModelicaConnectorCollection) { foreach (var dstPort in port.DstConnections.PortCompositionCollection .Select(c => c.DstEnds.ModelicaConnector) .Where(p => p.ParentContainer is CyPhy.ModelicaModel == false)) { CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPort(port); if (srcConnector == null) { continue; } CyPhy.ModelicaConnector dstConnector = null; if (dstPort.ParentContainer is CyPhy.Component) { dstConnector = this.GetModelicaModelConnectorFromComponentPort(dstPort); } else if (dstPort.ParentContainer is CyPhy.ComponentAssembly) { dstConnector = dstPort; } // The Fidelty Selected might not have this Connection - don't make it. // Or it might be a floating connector with no purpose. if (dstConnector == null) { continue; } var connection_mo = new Connection(srcConnector.Name, dstConnector.Name) { SrcInstanceName = component.Name, Type = srcConnector.Attributes.Class }; if (dstPort.ParentContainer.ID != ca.ID) { connection_mo.DstInstanceName = dstPort.ParentContainer.Name; } componentAssembly_mo.Connections.Add(connection_mo); } } // Connections from Connectors (Components) foreach (var portContainer in component.Children.ConnectorCollection) { if (portContainer.Children.ModelicaConnectorCollection.Count() != 1) { continue; } foreach (var dstPortContainer in portContainer.DstConnections.ConnectorCompositionCollection.Select(c => c.DstEnds.Connector)) { if (dstPortContainer.Children.ModelicaConnectorCollection.Count() != 1) { continue; } CyPhy.ModelicaConnector srcConnector = this.GetModelicaModelConnectorFromComponentPortContainer(portContainer); if (srcConnector == null) { continue; } CyPhy.ModelicaConnector dstConnector = null; string dstConnectorName = "ERROR No Name Assigned"; if (dstPortContainer.ParentContainer is CyPhy.Component) { var portComponent = CyPhyClasses.Component.Cast(dstPortContainer.ParentContainer.Impl); if (this.ComponentIsDynamic(portComponent) == false) { this.Logger.WriteWarning("'{0}' does not contain any dynamic-components, connections to it skipped.", portComponent.Name); continue; } dstConnector = this.GetModelicaModelConnectorFromComponentPortContainer(dstPortContainer); if (dstConnector != null) { dstConnectorName = dstConnector.Name; } } else if (dstPortContainer.ParentContainer is CyPhy.ComponentAssembly) { var portCA = dstPortContainer.ParentContainer.Impl; if (this.ContainsDynamicComponents(CyPhyClasses.ComponentAssembly.Cast(portCA)) == false) { this.Logger.WriteWarning("'{0}' does not contain any dynamic-components, connections to it skipped.", portCA.Name); continue; } dstConnector = dstPortContainer.Children.ModelicaConnectorCollection.FirstOrDefault(); dstConnectorName = dstPortContainer.Name.Replace(' ', '_'); } // The Fidelty Selected might not have this Connection - don't make it. // Or it might be a floating connector with no purpose. if (dstConnector == null) { continue; } var connection_mo = new Connection(srcConnector.Name, dstConnectorName) { SrcInstanceName = component.Name, Type = srcConnector.Attributes.Class }; if (dstPortContainer.ParentContainer.ID != ca.ID) { connection_mo.DstInstanceName = dstPortContainer.ParentContainer.Name; } componentAssembly_mo.Connections.Add(connection_mo); } } // Add limit-checks for the component to the test-bench foreach (var modelicaModelLimit in modelicaModel.Children.LimitCheckCollection) { // TODO: When META-1124 and META-1129 both are merged, merge Limit and LimitCheck class. var limit = new Limit(modelicaModelLimit) { ComponentModelicaUri = componentModelicaURI }; this.testBench_mo.Limits.Add(limit); var limitCheck = new LimitCheck() { ParentKind = modelicaModelLimit.ParentContainer.Kind, LimitFullPath = modelicaModelLimit.Path, LimitName = modelicaModelLimit.Name, VariableName = modelicaModelLimit.Attributes.VariableName, Type = modelicaModelLimit.Attributes.LimitType.ToString(), Value = modelicaModelLimit.Attributes.Value, VariableFullPath = string.Format("{0}.{1}", componentModelicaURI, modelicaModelLimit.Attributes.VariableName), ModelicaRecordName = string.Format("Limit{0}", this.testBench_mo.Limits.Count) }; this.LimitDefintion.LimitChecks.Add(limitCheck); } }
public CachingResult(IResult inner, ICacheManager cacheManager, ComponentInstance component) { this.inner = inner; this.cacheManager = cacheManager; this.component = component; }
private IResult Annotate(ComponentInstance component, IResult result) { return component.RenderingInstructions.AnnotateComponentPaths ? new AnnotatedResult(result, component.Path) : result; }