How to restore my entities color in editsketch state?
Liwei Jin
Hello, everyone. Hope you are doing well. I get a good help in previous post and now have another problem.
After changing entities color I finished new sketch. And I tried to edit sketch but every entity colors are cleaned. I wanna restore every entity colors.
Please someone help me. Thank you in advance. my codes are followings. If you want I can share my source code.
This code saves wrong entity color.
public static void editingcolors(List<Entity> entlist, List<Entity> allentlst)
{
if(entlist.Count == 0) return;
Color selClr = entlist.First().Color;
sketchColors.Clear();
selentities.Clear();
allentities.Clear();
selentities = entlist;
allentities= allentlst;
for (int i = 0; i < allentlst.Count; i++)
{
if (IsContainSelEnt(allentlst[i], entlist))
{
sketchColors.Add(i, selClr);
}
else
sketchColors.Add(i, allentlst[i].Color);
}
}
public void RestoreData(SketchManager sm)
{
projInfoPreOperation = SketchCurves.Select(x => x.SketchCurveData).ToArray();
if (projInfoPreOperation == null) return;
int lstIx = Math.Min(projInfoPreOperation.Length, SketchCurves.Length);
for (var i = 0; i < SketchCurves.Length/*lstIx*/; i++)
{
SketchCurve sketchCurve = SketchCurves[i];
try
{
Entity ent = sm.Map<Entity>(sketchCurve);
foreach (Entity en in selentities)
{
if (ent.GetType()==en.GetType()&&ent.Color==en.Color)
{
MessageBox.Show("Equal Entity");
sketchColors[i] = en.Color;
}
}
}
catch { }
}
for (var i = 0; i < SketchCurves.Length/*lstIx*/; i++)
{
SketchCurve sketchCurve = SketchCurves[i];
//sketchCurve.SketchCurveData = projInfoPreOperation[i];
try
{
Entity ent = sm.Map<Entity>(sketchCurve);
if (sketchColors.ContainsKey(i))
{
ent.Color = sketchColors[i];
ent.ColorMethod = colorMethodType.byEntity;
sm.UpdateAndInvalidate();
}
}
catch { }
}
}
public class LRedState : LMultipleSelectionState
{
private Entity _p1, _p2;
Color clr = Color.Red;
bool bAOR=false;
List<Entity> allent = new List<Entity>();
public LRedState(LDesign d) : base(d)
{
//d.Selection.Color = Color.Green;
foreach(Entity e in d.Entities)
allent.Add(e);
foreach (Entity en in d.SelectEntities)
{
en.ColorMethod = colorMethodType.byEntity;
en.Color = clr;
d.Entities.Regen();
d.Invalidate();
UpdateAndInvalidate();
entities.Add(en);
}
LSketchEntity.editingcolors(entities,allent);
}
protected override bool ValidForSelection(Entity en, int index)
{
return en is Point;
}
public override void OnMouseDown(MouseEventArgs mea)
{
Entity ent = GetEntityByPosition(RenderContextUtility.ConvertPoint(Design.GetMousePosition(mea)));
//if (ent == null || !Design.SketchManager.IsSketchEntity(ent) || !ValidForSelection(ent, entities.Count))
if (ent == null || !Design.SketchManager.IsSketchEntity(ent))
return;
int index = -1;
if (!entities.Contains(ent))
{
entities.Add(ent);
bAOR = true;
}
else
{
entities.Remove(ent);
bAOR=false;
}
for(int i = 0;i<entities.Count; i++)
{
if (ent == entities[i])
{
index=i; break;
}
}
if (!EntitySelected(ent, entities.Count - 1))
// end of multiple selection
Init();
}
protected override bool EntitySelected(Entity ent, int index)
{
List<Entity> entities1 = new List<Entity>();
foreach(Entity e in entities)
{
entities1.Add(e);
}
if(ent==null)
return false;
else
{
if (!bAOR)
{
ent.ColorMethod = colorMethodType.byEntity;
ent.Color = Color.White;
ent.Selected = false;
}
else
{
ent.ColorMethod = colorMethodType.byEntity;
ent.Color = clr;
ent.Selected = true;
}
entities.Clear();
foreach(Entity en in entities1)
{
entities.Add(en);
}
UpdateAndInvalidate();
LSketchEntity.editingcolors(entities,allent);
return true;
}
return false;
}
public override void Init()
{
UIMessage = "Select the first point";
base.Init();
}
}
0
Comments
Please sign in to leave a comment.