Skip to content

Commit 729ca67

Browse files
author
MrsSima
committed
xx2
1 parent 6b650fd commit 729ca67

File tree

27 files changed

+245
-153
lines changed

27 files changed

+245
-153
lines changed

ConstraintsMatcher/ConstraintsMatcher.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
3434
<ItemGroup>
35+
<Reference Include="QuickGraph">
36+
<HintPath>..\packages\QuickGraphPCL\lib\portable-win+net4+sl5+wp8+win8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\QuickGraph.dll</HintPath>
37+
</Reference>
38+
<Reference Include="QuickGraph.Graphviz">
39+
<HintPath>..\packages\QuickGraphPCL\lib\portable-win+net4+sl5+wp8+win8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\QuickGraph.Graphviz.dll</HintPath>
40+
</Reference>
3541
<Reference Include="System" />
3642
<Reference Include="System.Core" />
3743
<Reference Include="System.Xml.Linq" />

ConstraintsMatcher/Matcher.cs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace ConstraintsMatcher
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using System.Text.RegularExpressions;
89

910
public class Matcher
1011
{
@@ -30,6 +31,7 @@ public Matcher(IModel model)
3031
public bool PreCheck(IModel constraintsModel)
3132
{
3233
var Nodes = new List<INode>();
34+
//Find the root
3335
foreach (var node in constraintsModel.Nodes)
3436
{
3537
var inEdges = constraintsModel.Edges.Where(x => x.To == node).ToList();
@@ -44,26 +46,68 @@ public bool PreCheck(IModel constraintsModel)
4446
return false;
4547
}
4648
this.root = Nodes.FirstOrDefault();
49+
// Check if root is correct
4750
if ((this.root.Class.Name == "NotNode") || (this.root.Class.Name == "OrNode") || (this.root.Class.Name == "NoNodes"))
4851
{
49-
this.ErrorMsg = "The root should be NodeType from modrl or AllNodes.";
52+
this.ErrorMsg = "The root should be NodeType from model or AllNodes.";
5053
return false;
5154
}
55+
// Check ther there is only one outcoming edge from notNode
5256
var notNodes = constraintsModel.Nodes.Where(x => x.Class.Name == "NotNode");
5357
foreach(var notNode in notNodes)
5458
{
5559
if (constraintsModel.Edges.Where(x => x.From == notNode).ToList().Count() > 1)
5660
{
61+
this.ErrorMsg = "There should be only one outgoing edge from Not Node.";
5762
return false;
5863
}
5964
}
60-
//TODO check if tree
65+
//Check if there is no outgoing edges from noNodes
66+
var noNodes = constraintsModel.Nodes.Where(x => x.Class.Name == "NoNodes");
67+
foreach (var noNode in noNodes)
68+
{
69+
if (constraintsModel.Edges.Where(x => x.From == noNode).ToList().Count() > 0)
70+
{
71+
this.ErrorMsg = "There shouldn't be outgoing edges from NoNodes";
72+
return false;
73+
}
74+
}
75+
// Check if this constraint is a tree
76+
var visited = new HashSet<int>();
77+
if (!this.CheckIffTree(constraintsModel, this.root, visited))
78+
{
79+
this.ErrorMsg = "Constraints graph should have a tree structure.";
80+
return false;
81+
}
82+
6183
return true;
6284
}
6385

86+
public bool CheckIffTree(IModel constraintsModel, INode root, HashSet<int> visited)
87+
{
88+
visited.Add(root.GetHashCode());
89+
var outgoingEdges = constraintsModel.Edges.Where(x => x.From == root);
90+
foreach(var edge in outgoingEdges)
91+
{
92+
if (visited.Any(x => x == edge.To.GetHashCode()))
93+
{
94+
return false;
95+
}
96+
if (!CheckIffTree(constraintsModel, (INode)edge.To, visited))
97+
{
98+
return false;
99+
}
100+
}
101+
return true;
102+
}
64103
public bool Check(INode originRoot, INode constraintsRoot, IModel constraintsModel)
65104
{
66-
return this.InnerCheck(originRoot, constraintsRoot, constraintsModel);
105+
return this.InnerCheck(originRoot, constraintsRoot, constraintsModel);
106+
}
107+
108+
public bool AttrCheck(INode originRoot, INode constraintsRoot)
109+
{
110+
return this.AttributesAreIdentic(originRoot, constraintsRoot);
67111
}
68112

69113
private bool InnerCheck(INode targetRoot, INode constraintsRoot, IModel constraintsModel)
@@ -104,7 +148,7 @@ private bool InnerCheck(INode targetRoot, INode constraintsRoot, IModel constrai
104148
var constraintsToRoot = (INode)outConstraintsEdges.FirstOrDefault().To;
105149
var targetParentRoot = (INode)this.targetModel.Edges.Where(x => x.To == targetRoot).FirstOrDefault().From;
106150
var outParentTargetEdges = this.targetModel.Edges.Where(x => x.From == targetParentRoot);
107-
var innerCheck = outParentTargetEdges.Any(x => ElementsAreIdentic(constraintParentEdge, x) && this.InnerCheck((INode)x.To, constraintsToRoot, constraintsModel));
151+
var innerCheck = outParentTargetEdges.Any(x => ElementsAreIdentic(x, constraintParentEdge) && this.InnerCheck((INode)x.To, constraintsToRoot, constraintsModel));
108152
return !innerCheck;
109153
}
110154
if ((outConstraintsEdges.Count() > 0)&&(outConstraintsEdges.FirstOrDefault().To.Class.Name == "NoNodes"))
@@ -146,15 +190,22 @@ private bool FindEdge(IEnumerable<IEdge> outTargetEdges, IEdge edge)
146190
return false;
147191
}
148192

149-
public bool ElementsAreIdentic(IElement firstElement, IElement secondElement)
193+
public bool ElementsAreIdentic(IElement targetElement, IElement constraintsElement)
150194
{
151-
if (firstElement.Class.Name != secondElement.Class.Name)
195+
if ((targetElement.Class.Name != constraintsElement.Class.Name)||!AttributesAreIdentic(targetElement, constraintsElement))
152196
{
153197
return false;
154198
}
155-
foreach(var attr in firstElement.Attributes)
199+
return true;
200+
}
201+
202+
public bool AttributesAreIdentic(IElement targetElement, IElement constraintsElement)
203+
{
204+
foreach (var targetAttr in targetElement.Attributes)
156205
{
157-
if (secondElement.Attributes.Where(x => x.Name == attr.Name).FirstOrDefault().StringValue != attr.StringValue)
206+
var constraintsAttr = constraintsElement.Attributes.Where(x => x.Name == targetAttr.Name).FirstOrDefault();
207+
Regex regEx = new Regex(constraintsAttr.StringValue);
208+
if (!regEx.IsMatch(targetAttr.StringValue))
158209
{
159210
return false;
160211
}

src/AirSim/View/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void InitAndLaunchPlugins()
7777
var libs = new PluginLauncher<PluginConfig>();
7878
const string folder = "../../../plugins/SamplePlugin/bin";
7979
var dirs = new List<string>(System.IO.Directory.GetDirectories(folder));
80-
var config = new PluginConfig(this.model, null, null, this.Console, null, null);
80+
var config = new PluginConfig(this.model, null, null, this.Console, null);
8181
foreach (var dir in dirs)
8282
{
8383
libs.LaunchPlugins(dir, config);

src/EditorPluginInterfaces/PluginConfig.cs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,15 @@ public class PluginConfig
4848
/// </summary>
4949
public IElementProvider ElementProvider { get; }
5050

51-
/// <summary>
52-
///
53-
/// </summary>
54-
public Grid ConstraintsGrid { get; set; }
55-
56-
/// <summary>
57-
/// RightPanel
58-
/// </summary>
59-
public Grid RightPanel { get; set; }
60-
61-
/// <summary>
62-
/// SceneGrid
63-
/// </summary>
64-
public Grid SceneGrid { get; set; }
65-
66-
/// <summary>
67-
/// SceneGrid
68-
/// </summary>
69-
public Grid PaletteGrid { get; set; }
70-
7151
public delegate void Func(string modelName);
7252
public Func FuncCreateConstraintsModel;
7353
public Func OnMainModelChangedFunction;
7454

75-
public delegate void Func1(bool modelName);
76-
public Func1 FuncChangeSelectorVisibility;
77-
55+
public delegate void VisibilityFunc(bool isVisible);
56+
public VisibilityFunc FuncChangeSelectorVisibility;
7857

7958
public Action<String> OnMainModelChanged;
59+
8060
/// <summary>
8161
/// Initializes a new instance of <see cref="PluginConfig"/>
8262
/// </summary>
@@ -86,22 +66,13 @@ public class PluginConfig
8666
/// <param name="toolbar">Toolbar</param>
8767
/// <param name="console">Console</param>
8868
/// <param name="elementProvider">Element provider</param>
89-
public PluginConfig(IModel model, IScene scene, IToolbar toolbar, IConsole console, IElementProvider elementProvider, Grid constraintsGrid)
69+
public PluginConfig(IModel model, IScene scene, IToolbar toolbar, IConsole console, IElementProvider elementProvider)
9070
{
9171
this.Model = model;
9272
this.Scene = scene;
9373
this.Toolbar = toolbar;
9474
this.Console = console;
9575
this.ElementProvider = elementProvider;
96-
this.ConstraintsGrid = constraintsGrid;
9776
}
98-
99-
//public void AddGrids(Grid rightPanel, Grid sceneGrid, Grid paletteGrid)
100-
//{
101-
//
102-
// this.RightPanel = rightPanel;
103-
// this.SceneGrid = sceneGrid;
104-
// this.PaletteGrid = paletteGrid;
105-
//}
10677
}
10778
}

src/Repo/FacadeLayer/Model.fs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ and Model
5151
member this.UnderlyingModel = model
5252

5353
interface IModel with
54-
member this.Visible
55-
with get (): bool =
56-
isVisible
57-
and set (v: bool): unit =
58-
isVisible <- v
5954

6055
member this.CreateElement (``type``: IElement) =
6156
let unwrappedType = (``type`` :?> Element).UnderlyingElement

src/Repo/ModelBuilders/ConstraintsMetamodelBuilder.fs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ConstraintsMetamodelBuilder() =
5151
let edgeTargetNameAssociation = findAssociation metamodelAssociation "targetName"
5252

5353
let model = repo.CreateModel("ConstraintsMetamodel", metamodel)
54+
model.Properties <- model.Properties.Add ("IsVisible", false.ToString())
5455

5556
let (~+) (name, shape, isAbstract) =
5657
let node = infrastructure.Instantiate model metamodelNode :?> INode
@@ -78,6 +79,7 @@ type ConstraintsMetamodelBuilder() =
7879
edge
7980

8081
let abstractNode = +("AbstractNode", "", true)
82+
let initialNode = +("InitialNode", "View/Pictures/initialBlock.png", false)
8183
let finalNode = +("FinalNode", "View/Pictures/finalBlock.png", false)
8284

8385
let abstractMotorsBlock = +("AbstractMotorsBlock", "", true)
@@ -92,11 +94,10 @@ type ConstraintsMetamodelBuilder() =
9294
let timer = +("Timer", "View/Pictures/timerBlock.png", false)
9395

9496
let allNodes = +("AllNodes", "View/Pictures/allNodes.png", false)
95-
let anyNodes = +("AnyNodes", "View/Pictures/timerBlock.png", false)
96-
let noNodes = +("NoNodes", "View/Pictures/timerBlock.png", false)
97-
let andNode = +("AndNode", "View/Pictures/timerBlock.png", false)
98-
let orNode = +("OrNode", "View/Pictures/timerBlock.png", false)
99-
let notNode = +("NotNode", "View/Pictures/timerBlock.png", false)
97+
//let anyNodes = +("AnyNodes", "View/Pictures/timerBlock.png", false)
98+
let noNodes = +("NoNodes", "View/Pictures/noNodes.png", false)
99+
let orNode = +("OrNode", "View/Pictures/orNode.png", false)
100+
let notNode = +("NotNode", "View/Pictures/notNode.png", false)
100101

101102
let link = abstractNode ---> (abstractNode, "target", "Link")
102103
infrastructure.Element.AddAttribute link "guard" "AttributeKind.String" ""
@@ -111,9 +112,9 @@ type ConstraintsMetamodelBuilder() =
111112
abstractMotorsBlock --|> abstractNode
112113
timer --|> abstractNode
113114
allNodes --|> abstractNode
114-
anyNodes --|> abstractNode
115+
//anyNodes --|> abstractNode
115116
noNodes --|> abstractNode
116-
andNode --|> abstractNode
117+
//andNode --|> abstractNode
117118
orNode --|> abstractNode
118119
notNode --|> abstractNode
119120

src/Repo/ModelBuilders/ConstraintsTestModelBuilder.fs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Repo.Metametamodels
1717
open Repo.DataLayer
1818
open Repo.CoreSemanticLayer
1919
open Repo.InfrastructureSemanticLayer
20+
open System.Runtime.InteropServices
2021

2122
/// Initializes repository with test model conforming to Robots Metamodel, actual program that can be written by end-user.
2223
type ConstraintsTestModelBuilder() =
@@ -27,14 +28,14 @@ type ConstraintsTestModelBuilder() =
2728
let infrastructureMetamodel = infrastructure.Metamodel.Model
2829

2930
let metamodelAbstractNode = Model.findNode metamodel "AbstractNode"
30-
//let metamodelInitialNode = Model.findNode metamodel "InitialNode"
31+
let metamodelInitialNode = Model.findNode metamodel "InitialNode"
3132
let metamodelFinalNode = Model.findNode metamodel "FinalNode"
3233
let metamodelMotorsForward = Model.findNode metamodel "MotorsForward"
3334
let metamodelTimer = Model.findNode metamodel "Timer"
3435

3536
let metamodelAll = Model.findNode metamodel "AllNodes"
36-
let metamodelAny = Model.findNode metamodel "AnyNodes"
37-
let metamodelAnd = Model.findNode metamodel "AndNode"
37+
//let metamodelAny = Model.findNode metamodel "AnyNodes"
38+
3839
let metamodelOr = Model.findNode metamodel "OrNode"
3940
let metamodelNot = Model.findNode metamodel "NotNode"
4041
let metamodelNone = Model.findNode metamodel "NoNodes"
@@ -43,39 +44,20 @@ type ConstraintsTestModelBuilder() =
4344
let link = Model.findAssociationWithSource metamodelAbstractNode "target"
4445

4546
let model = repo.CreateModel("ConstraintsTestModel", metamodel)
47+
model.Properties <- model.Properties.Add ("IsVisible", false.ToString())
48+
let initialNode = infrastructure.Instantiate model metamodelInitialNode
4649

47-
//let initialNode = infrastructure.Instantiate model metamodelInitialNode
48-
let finalNode = infrastructure.Instantiate model metamodelFinalNode
49-
50-
let motorsForward = infrastructure.Instantiate model metamodelMotorsForward
51-
infrastructure.Element.SetAttributeValue motorsForward "ports" "M3, M4"
52-
infrastructure.Element.SetAttributeValue motorsForward "power" "100"
53-
54-
let motorsForward2 = infrastructure.Instantiate model metamodelMotorsForward
55-
infrastructure.Element.SetAttributeValue motorsForward2 "ports" "M3, M4"
56-
infrastructure.Element.SetAttributeValue motorsForward2 "power" "100"
57-
58-
let timer = infrastructure.Instantiate model metamodelTimer
59-
infrastructure.Element.SetAttributeValue timer "delay" "3000"
60-
61-
let notNode = infrastructure.Instantiate model metamodelNot
50+
let motorsForw = infrastructure.Instantiate model metamodelMotorsForward
51+
infrastructure.Element.SetAttributeValue motorsForw "ports" "M3, M4"
52+
infrastructure.Element.SetAttributeValue motorsForw "power" "10*"
6253

63-
let orNodes = infrastructure.Instantiate model metamodelOr
64-
65-
let timer2 = infrastructure.Instantiate model metamodelTimer
66-
infrastructure.Element.SetAttributeValue timer2 "delay" "3000"
67-
68-
let timer3 = infrastructure.Instantiate model metamodelTimer
69-
infrastructure.Element.SetAttributeValue timer3 "delay" "3000"
70-
7154

7255
let (-->) (src: IElement) dst =
7356
let aLink = infrastructure.Instantiate model link :?> IAssociation
7457
aLink.Source <- Some src
7558
aLink.Target <- Some dst
7659
dst
7760

78-
//initialNode -->
79-
finalNode --> timer --> motorsForward --> notNode --> timer2 |> ignore
80-
timer --> timer3 --> orNodes --> motorsForward2 |> ignore
61+
62+
motorsForw |> ignore
8163
()

src/Repo/ModelBuilders/RobotsMetamodelBuilder.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type RobotsMetamodelBuilder() =
5959
edge
6060

6161
let abstractNode = +("AbstractNode", "", true)
62-
// let initialNode = +("InitialNode", "View/Pictures/initialBlock.png", false)
62+
let initialNode = +("InitialNode", "View/Pictures/initialBlock.png", false)
6363
let finalNode = +("FinalNode", "View/Pictures/finalBlock.png", false)
6464

6565
let abstractMotorsBlock = +("AbstractMotorsBlock", "", true)

0 commit comments

Comments
 (0)