private void askColor() { // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var infoList = dataSet.GetSelectedObjectInfoList(); if (infoList.Count > 0) { dialogColor.Color = Color.FromArgb(255, infoList[0].Color); if (dialogColor.ShowDialog() == DialogResult.OK) { foreach (var info in infoList) { info.Color = Color.FromArgb(info.Color.A, dialogColor.Color); } dataSet.DoObjectInfoSetChanged(); } } } finally { _mutex.ReleaseMutex(); } }
private void numericColorAlpha_ValueChanged(object sender, EventArgs e) { // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_infoContentChanging) { return; } _infoContentChanging = true; try { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var infoList = dataSet.GetSelectedObjectInfoList(); int alpha = (int)(Math.Round(2.55 * (int)numericColorAlpha.Value)); if (infoList.Count > 0) { foreach (var info in infoList) { info.Color = Color.FromArgb(alpha, info.Color); } dataSet.DoObjectInfoSetChanged(); } } finally { _infoContentChanging = false; } } finally { _mutex.ReleaseMutex(); } }
private void treeViewInfo_AfterSelect(object sender, TreeViewEventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var pairList = _nodeByPath.Where(p => p.Value == e.Node).ToList(); if (pairList.Count > 0) { string path = pairList[0].Key; if (path != _currentGroup) { _currentGroup = path; if (!string.IsNullOrEmpty(_currentGroup)) { dataSet.SelectObjects(false); dataSet.SelectObjects(true, info => PathEx.IsSubPath(info.Name, _currentGroup)); } this.DoSelectedGroupChanged(); if (!string.IsNullOrEmpty(_currentGroup)) { if (listObjectInfo.Items.Count > 0) { listObjectInfo.Items[0].EnsureVisible(); } } } } }
/// <summary> /// モーションオブジェクトの欠損/被欠損の情報をフレーム単位で取得する /// </summary> /// <param name="id">情報を取得するさきのオブジェクトのId</param> /// <returns></returns> private RangeSet <int> getExistenceList(uint id) { MotionDataSet dataSet = _dataSet; if (dataSet == null) { return(null); } RangeSet <int> ret; if (_existenceList.TryGetValue(id, out ret)) { return(ret); } try { ret = new RangeSet <int>(); int index = 0; foreach (var frame in dataSet.EnumerateFrame()) { if (frame[id] != null) { ret.Add(new RangeSet <int> .Range(index, index + 1)); } index++; } _existenceList[id] = ret; return(ret); } catch { return(null); } }
private void checkVisible_CheckStateChanged(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_infoContentChanging) { return; } _infoContentChanging = true; try { var infoList = dataSet.GetSelectedObjectInfoList(); checkVisible.ThreeState = false; bool visible = checkVisible.Checked; if (infoList.Count > 0) { foreach (var info in infoList) { info.IsVisible = visible; } dataSet.DoObjectInfoSetChanged(); } } finally { _infoContentChanging = false; } } finally { _mutex.ReleaseMutex(); } }
private void textGroup_Validated(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var infoList = dataSet.GetSelectedObjectInfoList(); string to = PathEx.NormalizePath(textGroup.Text); if (to == _currentGroup) { return; } bool found = false; foreach (var info in infoList) { if (PathEx.IsSubPath(info.Name, _currentGroup)) { string subName = PathEx.GetRelativePath(info.Name, _currentGroup); _dataSet.RenameObjectInfo(info, PathEx.CombineName(to, subName), this); found = true; } } _currentGroup = to; if (found) { dataSet.DoObjectInfoSetChanged(); } }
public void DetachDataSet() { if (_dataSet != null) { _dataSet.ObjectSelectionChanged -= OnDataSetSelectedChanged; _dataSet.ObjectInfoSetChanged -= motionDataObjectSelectList_disposed; _dataSet = null; OnDataSetSelectedChanged(this, new EventArgs()); } }
private void buttonDown_Click(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } dataSet.ReorderObjectInfo(dataSet.GetSelectedObjectInfoList(), 1); }
public MotionDataViewerForm(MotionDataSet dataSet) { InitializeComponent(); if (dataSet == null) { throw new ArgumentNullException("dataSet", "'dataSet' cannot be null"); } _dataSet = dataSet; motionDataViewer1.AttachDataSet(dataSet); motionDataViewer1.AttachTimeController(TimeController.Singleton); }
private void removeToolStripMenuItem_Click(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } dataSet.RemoveSelectedObjects(true, this); }
/// <summary> /// オブジェクトからMotionDataSetの関連を解きます /// </summary> public void DetachDataSet() { lock (_lockDataSet) { if (_dataSet != null) { _dataSet.ObjectSelectionChanged -= OnSelectionChanged; _dataSet.ObjectInfoSetChanged -= OnObjectInfoSetChanged; _dataSet = null; } } }
/// <summary> /// オブジェクトにMotionDataSetを関連付けます /// </summary> /// <param name="dataSet"></param> public void AttachDataSet(MotionDataSet dataSet) { lock (_lockDataSet) { DetachDataSet(); _dataSet = dataSet; if (_dataSet != null) { _dataSet.ObjectSelectionChanged += OnSelectionChanged; _dataSet.ObjectInfoSetChanged += OnObjectInfoSetChanged; } OnObjectInfoSetChanged(this, null); } }
public void AttachDataSet(MotionDataSet dataSet, Predicate <MotionObjectInfo> targetCondition, Predicate <MotionObjectInfo> defaultSelectedCondition) { DetachDataSet(); _dataSet = dataSet; _targetCondition = targetCondition; _defaultSelectedCondition = defaultSelectedCondition; _dataSet.ObjectSelectionChanged += OnDataSetSelectedChanged; _dataSet.ObjectInfoSetChanged += OnDataSetSelectedChanged; OnDataSetSelectedChanged(this, new EventArgs()); if (listSelect.Items.Count > 0) { listSelect.SelectedIndex = 0; } }
private void showToolStripMenuItem_Click(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } foreach (var info in dataSet.GetSelectedObjectInfoList()) { info.IsVisible = true; } dataSet.DoObjectInfoSetChanged(); }
/// <summary> /// 既定のコンストラクタ /// </summary> /// <param name="dataSet"></param> /// <param name="sequenceController"></param> public OperationMenuCreator(MotionDataSet dataSet, Sequence.SequenceViewerController sequenceController) { if (dataSet == null) { throw new ArgumentNullException("dataSet", "'dataSet' cannot be null"); } if (sequenceController == null) { throw new ArgumentNullException("sequenceController", "'sequenceController' cannot be nul"); } _dataSet = dataSet; _sequenceController = sequenceController; InitializeMenus(); }
private string formatNameText(MotionObjectInfo info) { MotionDataSet dataSet = _dataSet; if (dataSet == null) { return(""); } string name = info.Name; if (_currentGroup != "") { name = name.Substring(_currentGroup.Length + 1); } return(formatNameText(name, dataSet.IsSelecting(info), info.IsVisible)); }
private void numericColorAlpha_MouseClick(object sender, MouseEventArgs e) { // 複数選択時に値が異なる場合には無効状態になるけどクリックしたら有効にする仕様 if (!numericColorAlpha.Enabled) { MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var infoList = dataSet.GetSelectedObjectInfoList(); if (infoList.Count > 0) { numericColorAlpha.Enabled = true; } } }
public void AttachDataSet(MotionDataSet dataSet) { lock (_lockAccessDataSet) { if (_dataSet != null) { _dataSet.ObjectSelectionChanged -= OnSelectedChanged; _dataSet.FrameListChanged -= _dataSet_FrameListChanged; } _dataSet = dataSet; if (_dataSet != null) { _dataSet.ObjectSelectionChanged += OnSelectedChanged; _dataSet.FrameListChanged += _dataSet_FrameListChanged; } } render(); }
private void replaceFirstToToolStripMenuItem_Click(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } foreach (var info in dataSet.GetSelectedObjectInfoList()) { int ub = info.Name.IndexOf('_'); if (ub >= 0) { dataSet.RenameObjectInfo(info, info.Name.Substring(0, ub) + "/" + info.Name.Substring(ub + 1), this); } } }
private void textName_Validated(object sender, EventArgs e) { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } string text = PathEx.NormalizePath(textName.Text); if (text == _defaultName) { return; } string newName = PathEx.CombineName(_currentGroup, text); dataSet.RenameSelectedObjects(newName, this); }
/// <summary> /// フレームデータをバイナリ形式から取得します /// </summary> /// <param name="reader"></param> /// <param name="parent"></param> /// <returns></returns> public static MotionFrame DeserializeBinary(BinaryReader reader, MotionDataSet parent) { decimal time = reader.ReadDecimal(); int count = reader.ReadInt32(); MotionFrame ret = new MotionFrame(parent, time, count); for (int i = 0; i < count; i++) { uint id = reader.ReadUInt32(); MotionObjectInfo info = parent.GetObjectInfoById(id); if (info == null) { throw new InvalidDataException(string.Format("unexpected id:{0} in frame at:{1}", id, time)); } MotionObject @object = info.GetEmptyObject(); @object.ReadBinary(reader); ret[info] = @object; } return(ret); }
private void DoUpdateObjectInfoControls() { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (this.InvokeRequired) { this.BeginInvoke(new Action(DoUpdateObjectInfoControls)); return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_infoContentChanging) { return; } _infoContentChanging = true; try { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var infoList = dataSet.GetSelectedObjectInfoList(); // その他のコントロールの更新 if (infoList.Count == 0) { // 選択なしのとき textColor.Enabled = false; textName.Enabled = false; numericColorAlpha.Enabled = false; checkVisible.Enabled = false; textGroup.Enabled = false; textColor.BackColor = Color.White; textColor.ForeColor = Color.Black; textColor.Text = "Color"; textName.Text = "Nothing selected"; numericColorAlpha.Value = 0; checkVisible.Checked = false; } else { textColor.Enabled = true; textName.Enabled = true; numericColorAlpha.Enabled = true; checkVisible.Enabled = true; textGroup.Enabled = true; // 名前 if (infoList.Count == 1) { textName.Text = PathEx.GetRelativePath(infoList[0].Name, _currentGroup); } else { textName.Text = _defaultName; } // 色 Color color = Color.FromArgb(255, infoList[0].Color); if (infoList.All(info => color == Color.FromArgb(255, info.Color))) { textColor.BackColor = color; textColor.ForeColor = ColorEx.GetComplementaryColor(color); textColor.Text = "Color: " + ColorTranslator.ToHtml(color); } else { textColor.BackColor = Color.White; textColor.ForeColor = Color.Black; textColor.Text = "Color: ..."; } // visible bool visible = infoList[0].IsVisible; if (infoList.All(info => visible == info.IsVisible)) { checkVisible.ThreeState = false; checkVisible.Checked = visible; } else { checkVisible.ThreeState = true; checkVisible.CheckState = CheckState.Indeterminate; } // 色のアルファ int alpha = infoList[0].Color.A; if (infoList.All(info => info.Color.A == alpha)) { numericColorAlpha.Value = (int)Math.Round(100.0 * alpha / 255); numericColorAlpha.ForeColor = SystemColors.ControlText; } else { numericColorAlpha.Value = (int)Math.Round(100.0 * alpha / 255); numericColorAlpha.ForeColor = SystemColors.GrayText; } } } finally { _infoContentChanging = false; } } finally { _mutex.ReleaseMutex(); } }
/// <summary> /// 外部でMotionDataSetのMotionObjectInfoの内容が変更されたので,ツリー及びオブジェクトの選択を変更する. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnObjectInfoSetChanged(object sender, EventArgs e) { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (treeViewInfo.InvokeRequired) { treeViewInfo.BeginInvoke(new EventHandler(OnObjectInfoSetChanged), sender, e); return; } MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_selectionChanging) { return; } _selectionChanging = true; try { HashSet <string> newGroups = new HashSet <string>(); newGroups.Add(""); foreach (var info in dataSet.GetObjectInfoList()) { string path = PathEx.DirName(info.Name); while (path != "") { if (!newGroups.Contains(path)) { newGroups.Add(path); } path = PathEx.DirName(path); } } HashSet <string> oldGroups = new HashSet <string>(_nodeByPath.Keys); if (newGroups.All(g => oldGroups.Contains(g)) && oldGroups.All(g => newGroups.Contains(g))) { // 変化なし } else { treeViewInfo.SuspendLayout(); try { treeViewInfo.Nodes.Clear(); _nodeByPath.Clear(); _nodeByPath[""] = new TreeNode("/"); foreach (var info in dataSet.GetObjectInfoList()) { string path = PathEx.DirName(info.Name); while (path != "") { if (!_nodeByPath.ContainsKey(path)) { _nodeByPath[path] = new TreeNode(PathEx.BaseName(path)); } path = PathEx.DirName(path); } } foreach (var pair in _nodeByPath) { string path = pair.Key; if (path != "") { string parent = PathEx.DirName(path); _nodeByPath[parent].Nodes.Add(pair.Value); } } treeViewInfo.Nodes.Add(_nodeByPath[""]); } finally { treeViewInfo.ResumeLayout(); } } this.DoSelectedGroupChanged(); this.DoUpdateObjectInfoControls(); } finally { _selectionChanging = false; } } finally { _mutex.ReleaseMutex(); } }
private void listObjectInfo_SelectedIndexChanged(object sender, EventArgs e) { // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_selectionChanging) { return; } _selectionChanging = true; try { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } HashSet <uint> selectedIds = new HashSet <uint>(); foreach (ListViewItem item in listObjectInfo.SelectedItems) { uint id = uint.Parse(item.SubItems[1].Text); selectedIds.Add(id); } HashSet <uint> changedIds = new HashSet <uint>(); foreach (var info in dataSet.GetObjectInfoList()) { bool selected = selectedIds.Contains(info.Id); if (dataSet.IsSelecting(info) != selected) { changedIds.Add(info.Id); dataSet.SelectObjects(selected, info); } } foreach (ListViewItem item in listObjectInfo.Items) { uint id = uint.Parse(item.SubItems[1].Text); if (changedIds.Contains(id)) { MotionObjectInfo info = dataSet.GetObjectInfoById(id); if (info != null) { item.Text = formatNameText(info); if (dataSet.IsSelecting(info)) { item.EnsureVisible(); item.Font = new Font(item.Font, FontStyle.Bold); } else { item.Font = new Font(item.Font, FontStyle.Regular); } } } } dataSet.DoObjectSelectionChanged(); this.DoUpdateObjectInfoControls(); } finally { _selectionChanging = false; } } finally { _mutex.ReleaseMutex(); } }
private void bgwRender_DoWork(object sender, DoWorkEventArgs e) { TimeController timeController = _timeController; MotionDataSet dataSet = _dataSet; if (dataSet == null || timeController == null) { Bitmap infoImage = new Bitmap(_width, _height); using (Graphics gfx = Graphics.FromImage(infoImage)) { gfx.Clear(Color.DimGray); gfx.DrawString("Error...", this.Font, Brushes.LightGray, new PointF()); } setPictureImage(pictGraph, infoImage); return; } RangeSet <int> existAll = null; // 選択されたオブジェクトが被欠損なインデックス List <int> clipIndices = new List <int>(); // グラフ上の各x座標のインデックスの範囲 Collection <MotionObjectInfo> infoList; // メッセージを表示 setText(labelInfo, "データ欠損情報"); infoList = dataSet.GetSelectedObjectInfoList(); if (infoList.Count == 0) { Bitmap infoImage = new Bitmap(_width, _height); using (Graphics gfx = Graphics.FromImage(infoImage)) { gfx.Clear(Color.DimGray); gfx.DrawString("選択オブジェクトなし", this.Font, Brushes.Ivory, new PointF()); } setPictureImage(pictGraph, infoImage); return; } else { Bitmap infoImage = new Bitmap(_width, _height); using (Graphics gfx = Graphics.FromImage(infoImage)) { gfx.Clear(Color.DimGray); gfx.DrawString("読み込み中...", this.Font, Brushes.LightGray, new PointF()); } setPictureImageImmediate(pictGraph, infoImage); } // 選択された全オブジェクトの非欠損のandを取る foreach (var info in infoList) { if (bgwRender.CancellationPending) { e.Cancel = true; return; } if (existAll == null) { existAll = getExistenceList(info.Id); } else { existAll = existAll.GetIntersect(getExistenceList(info.Id)); } } // 各x座標に対応する時間に対応するフレームのインデックスを求める // clipIndices[0] から (clipIndices[1] - 1)には,[x=0に対応する時刻]から[x=1に対応する時刻の直前]までに含まれるインデックスが入るようにする for (int x = 0; x <= _width; x++) { decimal time = positionToTime(x); int index = dataSet.GetFrameIndexAt(time); // ちょうどtimeの値がフレームの時間と一緒のときだけ特別対応 Motion.MotionFrame frame = dataSet.GetFrameByIndex(index); if (frame == null || frame.Time != time) { index++; // 取得されたインデックスは,今回のループのx座標に対応する時間範囲に入らない } clipIndices.Add(index); } lock (_lockAccessGraphImage) { // グラフの作成 _graphImage = new Bitmap(_width, _height); using (Graphics gfx = Graphics.FromImage(_graphImage)) { gfx.Clear(Color.Black); for (int x = 0; x < _width; x++) { // 今回のx座標に対応するフレームインデックスの範囲 int clipCount = clipIndices[x + 1] - clipIndices[x]; RangeSet <int> .Range clipRange = new RangeSet <int> .Range(clipIndices[x], clipIndices[x + 1]); // 今回の範囲の被欠損情報を取得 RangeSet <int> existClipped = existAll.GetClipped(clipRange); int existCount = existClipped.Total(); Pen pen = Pens.LightGreen; if (existCount == clipCount) { pen = Pens.YellowGreen; } if (existCount > 0) { gfx.DrawLine(pen, new Point(x, _height - 1), new Point(x, _height - 1 - _height * existCount / clipCount)); } } // 選択範囲の欠損割合の計算 decimal selectBegin = timeController.VisibleBeginTime; decimal selectEnd = timeController.VisibleEndTime; int selectBeginIndex = dataSet.GetFrameIndexAt(selectBegin); int selectEndIndex = dataSet.GetFrameIndexAt(selectEnd); MotionFrame selectBeginFrame = dataSet.GetFrameByIndex(selectBeginIndex); MotionFrame selectEndFrame = dataSet.GetFrameByIndex(selectEndIndex); if (selectBeginFrame == null || selectBeginFrame.Time != selectBegin) { selectBeginIndex++; // clipIndicesを求めるときと同じ処理 } if (selectEndFrame == null || selectEndFrame.Time != selectEnd) { selectEndIndex++; } RangeSet <int> whole = existAll.GetClipped(new RangeSet <int> .Range(selectBeginIndex, selectEndIndex)); int selectClipCount = selectEndIndex - selectBeginIndex; int selectExistCount = whole.Total(); int missingCount = selectClipCount - selectExistCount; double percentage = selectClipCount == 0 ? 0 : (100.0 - 100.0 * selectExistCount / selectClipCount); setText(labelInfo, string.Format("欠落フレーム数: {0} (選択フレーム数 {1}, {2}% 欠損) ({3} オブジェクト)", missingCount, selectClipCount, Math.Round(percentage, 2), infoList.Count)); } } }
public MotionProcEnv(ScriptConsole console) { this.DataSet = console.MotionDataSet; this.SequenceController = console.SequenceController; }
public ScriptVariable Call(IList <ScriptVariable> args, ScriptConsole console) { _progress.Initialize(0, "Initializing..."); if (args == null) { throw new ArgumentNullException("args", "args cannot be null"); } if (args.Count < 1) { args = new List <ScriptVariable> { null } } ; if (args[0] == null) { args[0] = new ListVariable(); } IList <ScriptVariable> objectNamesVar = args[0].ToList(); if (objectNamesVar.Any(n => n.IsNull())) { throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ObjectNameCannotBeNull, "args"); } List <string> objectNames = objectNamesVar.Select(n => n.ToString()).ToList(); MotionDataSet dataSet = console.MotionDataSet; MotionProcEnv env2 = new MotionProcEnv(console); List <MotionObjectInfo> infoList = new List <MotionObjectInfo>(); foreach (string objectName in objectNames) { MotionObjectInfo info = dataSet.GetObjectInfoByName(objectName); if (info == null) { throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ObjectNotFound + ": " + objectName, "args"); } infoList.Add(info); } foreach (MotionObjectInfo info in infoList) { if (!_operation.FilterSelection(info)) { throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidTargetObjectSpecified + ": " + info.Name, "args"); } } string errorMessage = ""; if (!_operation.ValidateSelection(infoList, ref errorMessage)) { if (errorMessage == null) { errorMessage = ""; } throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ImproperObjectSelection + ": " + errorMessage, "args"); } IList <ProcParam <MotionProcEnv> > parameters = _operation.GetParameters() ?? new ProcParam <MotionProcEnv> [0]; if (args.Count != parameters.Count + 1) { throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_NumberOfArgumentsRequired, parameters.Count + 1)); } for (int i = 0; i < parameters.Count; i++) { if (!parameters[i].FromScriptVariable(env2, args[i + 1], ref errorMessage)) { throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidNthArgument + ": {1}", i + 1, errorMessage ?? ""), "args"); } } if (!_operation.ValidateArguments(parameters, ref errorMessage)) { throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidArgument + ": {0}", errorMessage ?? ""), "args"); } IMotionOperationGeneral general = _operation as IMotionOperationGeneral; if (general != null) { _progress.Initialize(0, "Operation"); general.Operate(infoList, parameters, dataSet, _progress); return(new ListVariable(infoList.Select(info => new StringVariable(info.Name)))); } IMotionOperationEditObject edit = _operation as IMotionOperationEditObject; if (edit != null) { _progress.Initialize(dataSet.FrameLength, "Edit Object"); foreach (MotionFrame frame in dataSet.EnumerateFrame()) { IList <MotionObject> results = edit.EditObject(infoList, parameters, new ReadOnlyMotionFrame(frame), false); int count = Math.Min(results.Count, infoList.Count); for (int i = 0; i < count; i++) { frame[infoList[i]] = results[i]; } _progress.CurrentValue++; } dataSet.DoFrameListChanged(); return(new ListVariable(infoList.Select(info => new StringVariable(info.Name)))); } IMotionOperationOutputSequence output = _operation as IMotionOperationOutputSequence; if (output != null) { _progress.Initialize(0, "Output"); IList <Sequence.SequenceData> sequences = output.OutputSequence(infoList, parameters, dataSet.EnumerateFrame().Select(frame => new ReadOnlyMotionFrame(frame)), _progress); foreach (Sequence.SequenceData sequence in sequences) { console.SequenceController.AddSequence(sequence); } return(new ListVariable(sequences.Select(s => new StringVariable(s.Title)))); } IMotionOperationCreateObject create = _operation as IMotionOperationCreateObject; if (create != null) { _progress.Initialize(dataSet.FrameLength, "Create Object"); IList <MotionObjectInfo> newInfoList = create.GetNewObjectInfoList(infoList, parameters); MotionFrame firstFrame = dataSet.GetFrameByIndex(0); if (firstFrame != null) { IList <MotionObject> newObjects = create.CreateObjects(infoList, parameters, new ReadOnlyMotionFrame(firstFrame), false) ?? new MotionObject[0]; if (newObjects.Count != newInfoList.Count) { throw new InvalidOperationException(global::MotionDataHandler.Properties.Settings.Default.Msg_CreateObjectLengthMismatch); } } foreach (MotionObjectInfo newInfo in newInfoList) { dataSet.AddObject(newInfo); } foreach (MotionFrame frame in dataSet.EnumerateFrame()) { IList <MotionObject> newObjects = create.CreateObjects(infoList, parameters, new ReadOnlyMotionFrame(frame), false) ?? new MotionObject[0]; int count = Math.Min(newObjects.Count, newInfoList.Count); for (int i = 0; i < count; i++) { frame[newInfoList[i]] = newObjects[i]; } _progress.CurrentValue++; } dataSet.DoObjectInfoSetChanged(); dataSet.DoFrameListChanged(); return(new ListVariable(newInfoList.Select(info => new StringVariable(info.Name)))); } return(null); }
public void AttachDataSet(MotionDataSet dataSet, IEnumerable <Type> targetTypes, bool?selectedOrNotSelected) { this.AttachDataSet(dataSet, new Predicate <MotionObjectInfo>(info => targetTypes.Any(type => info.IsTypeOf(type))), new Predicate <MotionObjectInfo>(info => selectedOrNotSelected.HasValue ? dataSet.IsSelecting(info) == selectedOrNotSelected.Value : false)); }
private void DoSelectedGroupChanged() { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (this.InvokeRequired) { this.Invoke(new Action(this.DoSelectedGroupChanged)); return; } MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } if (!_mutex.WaitOne(0)) { return; } try { // グループの選択 if (_currentGroup == "") { textGroup.Text = PathEx.PathSeparator.ToString(); groupBoxInformation.Text = "<Object Information>"; } else { textGroup.Text = _currentGroup; groupBoxInformation.Text = string.Format("<Object Information - {0}>", _currentGroup); } // グループ外のオブジェクトの選択をやめる foreach (var info in dataSet.GetObjectInfoList()) { if (!PathEx.IsSubPath(info.Name, _currentGroup)) { dataSet.SelectObjects(false, info); } } // 前回のフォーカスを持ったオブジェクト uint? prevFocusedId = null; ListViewItem focusedItem = listObjectInfo.FocusedItem; if (focusedItem != null) { prevFocusedId = uint.Parse(focusedItem.SubItems[1].Text); } // 現在の属するグループにEnsureVisible TreeNode currentNode; if (_nodeByPath.TryGetValue(_currentGroup, out currentNode)) { invokeControl(treeViewInfo, () => { treeViewInfo.SelectedNode = currentNode; currentNode.EnsureVisible(); }); } listObjectInfo.SuspendLayout(); try { listObjectInfo.Items.Clear(); var infoList = dataSet.GetObjectInfoListByGroup(_currentGroup); ListViewItem lastSelected = null; ListViewItem lastFocused = null; foreach (var info in infoList) { ListViewItem item = new ListViewItem(formatNameText(info)); item.UseItemStyleForSubItems = false; ListViewItem.ListViewSubItem id = new ListViewItem.ListViewSubItem(item, info.Id.ToString()); ListViewItem.ListViewSubItem type = new ListViewItem.ListViewSubItem(item, info.ObjectType.Name); item.SubItems.Add(id); item.SubItems.Add(type); id.BackColor = Color.FromArgb(255, info.Color); id.ForeColor = ColorEx.GetComplementaryColor(id.BackColor); item.Selected = dataSet.IsSelecting(info); listObjectInfo.Items.Add(item); if (dataSet.IsSelecting(info)) { lastSelected = item; } if (prevFocusedId.HasValue && info.Id == prevFocusedId.Value) { lastFocused = item; } } if (lastSelected != null) { lastSelected.EnsureVisible(); } if (lastFocused != null) { lastFocused.Focused = true; } } finally { listObjectInfo.ResumeLayout(); } dataSet.DoObjectSelectionChanged(); } finally { _mutex.ReleaseMutex(); } }
public void OnSelectionChanged(object sender, EventArgs e) { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (this.InvokeRequired) { this.BeginInvoke(new EventHandler(OnSelectionChanged), sender, e); return; } // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_selectionChanging) { return; } _selectionChanging = true; try { // リストビューの更新 listObjectInfo.SuspendLayout(); try { var infoList = dataSet.GetSelectedObjectInfoList(); // 選択されたオブジェクトが現在の選択グループ以外のものを含む場合にグループの選択を上位に変更 if (infoList.Count != 0) { string common = PathEx.GetCommonDir(infoList.Select(info => info.Name).ToList()); if (_currentGroup != common && !PathEx.IsSubPath(common, _currentGroup)) { _currentGroup = common; this.DoSelectedGroupChanged(); return; } } ListViewItem lastSelected = null; // 選択が変更されたオブジェクトについてのリストビューのアイテムを更新 foreach (ListViewItem item in listObjectInfo.Items) { uint id = uint.Parse(item.SubItems[1].Text); var info = dataSet.GetObjectInfoById(id); if (info != null) { if (item.Selected != dataSet.IsSelecting(info)) { if (dataSet.IsSelecting(info)) { lastSelected = item; } item.Text = formatNameText(info); item.Selected = dataSet.IsSelecting(info); item.Font = new Font(item.Font, dataSet.IsSelecting(info) ? FontStyle.Bold : FontStyle.Regular); } } } if (lastSelected != null) { lastSelected.EnsureVisible(); } } finally { listObjectInfo.ResumeLayout(); } this.DoUpdateObjectInfoControls(); } finally { _selectionChanging = false; } } finally { _mutex.ReleaseMutex(); } }