Skip to content

Commit

Permalink
Add page with binding
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillGutyrchik committed Aug 16, 2024
1 parent 3d36ae5 commit 2d281df
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/IO/IOManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ private void InitIoModulesInfo()
if (!File.Exists(pathToFile))
NoFileErrorShow(templateName, pathToFile);

object[] result = lua.DoFile(pathToFile);
object[] result = lua.DoString(
new StreamReader(pathToFile, EncodingDetector.DetectFileEncoding(pathToFile), true)
.ReadToEnd());

if (result == null)
return;

Expand Down
66 changes: 61 additions & 5 deletions src/ProjectImport/ProjectImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,35 @@ public class ProjectImporter
private const string PLC_BUS = "Шина ПЛК";

/// <summary>
/// Тип страницы для вставки макроса
/// Тип страницы для вставки макроса "Обзор"
/// </summary>
private static readonly DocumentTypeManager.DocumentType OVERVIEW_DOC = DocumentTypeManager.DocumentType.Overview;

/// <summary>
/// Тип представления макроса "Обзор"
/// </summary>
private static readonly WindowMacro.Enums.RepresentationType OVERVIEW = WindowMacro.Enums.RepresentationType.Overview;

/// <summary>
/// Тип страницы "Многополосная схема соединения"
/// </summary>
private static readonly DocumentTypeManager.DocumentType CIRCUIT_DOC = DocumentTypeManager.DocumentType.Circuit;

/// <summary>
/// Тип представления макроса "Многополосный"
/// </summary>
private static readonly WindowMacro.Enums.RepresentationType MULTILINE = WindowMacro.Enums.RepresentationType.MultiLine;

/// <summary>
/// Вариант Е макроса - модуль на Overview
/// </summary>
private static readonly int MACRO_VARIANT_E = 4;

/// <summary>
/// Вариант A макроса - клеммы на ...
/// </summary>
private static readonly int MACRO_VARIANT_A = 0;

/// <summary>
/// Начальный отступ слева страницы для вставки узла и модулей (мм)
/// </summary>
Expand Down Expand Up @@ -212,7 +232,7 @@ public bool ImportNode(int nodeType, int nodeIndex, string IP)

currentPage = new Page();

currentPage.Create(project, DocumentTypeManager.DocumentType.Overview, pageProperties);
currentPage.Create(project, OVERVIEW_DOC, pageProperties);
currentPage.LockObject();
currentPage.Properties.PAGE_NOMINATIOMN = PLC_BUS;

Expand Down Expand Up @@ -309,9 +329,9 @@ private WindowMacro OpenMacro(int number)
public bool ImportModule(int moduleN, int nodeIndex, int moduleIndex)
{
var macro = OpenMacro(moduleN);
var moduleInfo = IOModuleInfo.GetModuleInfo($"750-{moduleN}", out var isStub);

StorableObject[] objects =
Insert.WindowMacro(macro,
var objects = Insert.WindowMacro(macro,
OVERVIEW, MACRO_VARIANT_E, currentPage,
new PointD(
X_OFFSET + currentNodeWidth + (moduleIndex - 1) % MODULES_IN_LINE * MODULE_WIDTH,
Expand All @@ -331,7 +351,8 @@ public bool ImportModule(int moduleN, int nodeIndex, int moduleIndex)
FUNC_COUNTER = moduleNumber,
}, $"-A{moduleNumber}");

var moduleInfo = IOModuleInfo.GetModuleInfo($"750-{moduleN}", out var isStub);
if (moduleN != 600) // exclude end module
CreatePageWithModuleBinding(macro, moduleInfo, moduleNumber);

Logs.AddMessage($"\t-A{moduleNumber} [ {moduleInfo.Name} ] {(isStub ? "Неопределенный модуль" : moduleInfo.Description)};\n");

Expand All @@ -340,5 +361,40 @@ public bool ImportModule(int moduleN, int nodeIndex, int moduleIndex)

return false;
}

public bool CreatePageWithModuleBinding(WindowMacro macro, IOModuleInfo moduleInfo, int moduleNumber)
{
var page = new Page();

page.Create(project, CIRCUIT_DOC, pageProperties);
page.LockObject();
page.Properties.PAGE_NOMINATIOMN = $"{moduleInfo.TypeName}. {moduleInfo.Number}";

// Rename Number of page (Перенос страницы Шины ПЛК в конец)
var name = currentPage.Properties.PAGE_NAME;
page.Properties.PAGE_NAME = name;
currentPage.Properties.PAGE_NAME = name + 1;

var objects = Insert.WindowMacro(macro,
MULTILINE, MACRO_VARIANT_A, page,
new PointD(X_OFFSET, PAGE_HEIGHT - Y_OFFSET),
Insert.MoveKind.Absolute);

var moduleClamp = objects?.OfType<PLC>().FirstOrDefault();
if (moduleClamp != null)
{
nameService.SetVisibleNameAndAdjustFullName(
currentPage, moduleClamp,
new FunctionPropertyList()
{
FUNC_CODE = "A",
FUNC_COUNTER = moduleNumber,
}, $"-A{moduleNumber}");

return true;
}

return false;
}
}
}

0 comments on commit 2d281df

Please sign in to comment.