!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Sandbox / Plugins / EditorSchematyc2 / Bridge / Private / Bridge_LibUtils.cpp
blob0100ebdd5973a9c57cd21dbea3c8a848ee54bdcc
1 // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "StdAfx.h"
4 #include "Bridge_LibUtils.h"
6 #include "CrySchematyc2/LibUtils.h"
8 namespace Schematyc2 {
10 namespace LibUtils {
12 void FindReferences(SGUID refGuid, SGUID refGoBack, const char* szItemName, const TScriptFile* pFile, SReferencesLogInfo& result)
14 result.header.Format("Searching references of %s in %s", szItemName, pFile->GetFileName());
16 auto visitAbstractInterfaces = [refGuid, refGoBack, szItemName, &result](const IScriptAbstractInterfaceImplementation& abstractInterface)->EVisitStatus
18 std::stack<string> path;
19 if (abstractInterface.GetRefGUID() == refGuid)
21 stack_string graphPath;
22 graphPath.append("<font color = \"yellow\">");
23 const IScriptElement *pParent = abstractInterface.GetParent();
24 while (pParent)
26 path.push(pParent->GetName());
27 pParent = pParent->GetParent();
30 while (!path.empty())
32 graphPath.append(path.top().c_str());
33 graphPath.append("<font color = \"black\">");
34 graphPath.append("//");
35 graphPath.append("<font color = \"yellow\">");
36 path.pop();
39 graphPath.append(abstractInterface.GetName());
41 SLogMetaItemGUID gotoItem(abstractInterface.GetGUID());
42 SLogMetaChildGUID gobackItem(refGoBack);
44 stack_string pathLink;
45 pathLink.Format("Reference of <font color = \"yellow\">%s <font color = \"lightgray\">found in %s", szItemName, graphPath.c_str());
47 result.references.emplace_back(gotoItem, gobackItem, pathLink.c_str());
50 return EVisitStatus::Continue;
53 auto visitGraph = [refGuid, refGoBack, szItemName, &result](const IDocGraph& graph) -> EVisitStatus
55 auto visitNode = [refGuid, refGoBack, &graph, szItemName, &result](const IScriptGraphNode& node) -> EVisitStatus
57 bool foundInOutput(false);
58 for (size_t i = 0, count = node.GetOutputCount(); i < count; ++i)
60 CAggregateTypeId typeId = node.GetOutputTypeId(i);
61 if (typeId.AsScriptTypeGUID() == refGuid)
63 foundInOutput = true;
64 break;
68 std::stack<string> path;
69 if (node.GetRefGUID() == refGuid || graph.GetContextGUID() == refGuid || foundInOutput)
71 stack_string graphPath;
72 graphPath.append("<font color = \"yellow\">");
73 const IScriptElement *parent = graph.GetParent();
74 while (parent)
76 path.push(parent->GetName());
77 parent = parent->GetParent();
80 while (!path.empty())
82 graphPath.append(path.top().c_str());
83 graphPath.append("<font color = \"black\">");
84 graphPath.append("//");
85 graphPath.append("<font color = \"yellow\">");
86 path.pop();
89 graphPath.append(graph.GetName());
91 SLogMetaItemGUID gotoItem(graph.GetType() == EScriptGraphType::Transition ? graph.GetScopeGUID() : graph.GetGUID());
92 SLogMetaChildGUID gobackItem(refGoBack);
94 stack_string pathLink;
95 pathLink.Format("Reference of <font color = \"yellow\">%s <font color = \"lightgray\">found in %s", szItemName, graphPath.c_str());
97 result.references.emplace_back(gotoItem, gobackItem, pathLink.c_str());
100 return EVisitStatus::Continue;
103 graph.VisitNodes(ScriptGraphNodeConstVisitor::FromLambdaFunction(visitNode));
104 return EVisitStatus::Continue;
107 auto visitActions = [refGuid, refGoBack, szItemName, &result](const IScriptActionInstance& action)->EVisitStatus
109 std::stack<string> path;
110 if (action.GetActionGUID() == refGuid)
112 stack_string graphPath;
113 graphPath.append("<font color = \"yellow\">");
114 const IScriptElement *parent = action.GetParent();
115 while (parent)
117 path.push(parent->GetName());
118 parent = parent->GetParent();
121 while (!path.empty())
123 graphPath.append(path.top().c_str());
124 graphPath.append("<font color = \"black\">");
125 graphPath.append("//");
126 graphPath.append("<font color = \"yellow\">");
127 path.pop();
130 graphPath.append(action.GetName());
132 SLogMetaItemGUID gotoItem(action.GetGUID());
133 SLogMetaChildGUID gobackItem(refGoBack);
135 stack_string pathLink;
136 pathLink.Format("Reference of <font color = \"yellow\">%s <font color = \"lightgray\">found in %s", szItemName, graphPath.c_str());
138 result.references.emplace_back(gotoItem, gobackItem, pathLink.c_str());
141 return EVisitStatus::Continue;
144 auto visitComponentInstances = [refGuid, refGoBack, szItemName, &result](const IScriptComponentInstance& componentInstance) -> EVisitStatus
146 if (const IScriptGraphExtension* pGraph = static_cast<const IScriptGraphExtension*>(componentInstance.GetExtensions().QueryExtension(Graph)))
148 const IScriptElement& graph = pGraph->GetElement_New();
150 auto visitNode = [refGuid, refGoBack, &graph, szItemName, &result, &componentInstance](const IScriptGraphNode& node) -> EVisitStatus
152 std::stack<string> path;
153 if (node.GetRefGUID() == refGuid)
155 stack_string graphPath;
156 graphPath.append("<font color = \"yellow\">");
157 const IScriptElement *parent = graph.GetParent();
158 while (parent)
160 path.push(parent->GetName());
161 parent = parent->GetParent();
164 while (!path.empty())
166 graphPath.append(path.top().c_str());
167 graphPath.append("<font color = \"black\">");
168 graphPath.append("//");
169 graphPath.append("<font color = \"yellow\">");
170 path.pop();
173 graphPath.append(graph.GetName());
175 SLogMetaItemGUID gotoItem(componentInstance.GetGUID());
176 SLogMetaChildGUID gobackItem(refGoBack);
178 stack_string pathLink;
179 pathLink.Format("Reference of <font color = \"yellow\">%s <font color = \"lightgray\">found in %s", szItemName, graphPath.c_str());
181 result.references.emplace_back(gotoItem, gobackItem, pathLink.c_str());
184 return EVisitStatus::Continue;
187 pGraph->VisitNodes(ScriptGraphNodeConstVisitor::FromLambdaFunction(visitNode));
190 return EVisitStatus::Continue;
193 pFile->VisitGraphs(DocGraphConstVisitor::FromLambdaFunction(visitGraph), SGUID(), true);
194 pFile->VisitComponentInstances(ScriptComponentInstanceConstVisitor::FromLambdaFunction(visitComponentInstances), SGUID(), true);
195 pFile->VisitActionInstances(ScriptActionInstanceConstVisitor::FromLambdaFunction(visitActions), SGUID(), true);
196 pFile->VisitAbstractInterfaceImplementations(ScriptAbstractInterfaceImplementationConstVisitor::FromLambdaFunction(visitAbstractInterfaces), SGUID(), true);
198 result.footer.Format("References found: %d", result.GetReferenceCount());
201 void FindAndLogReferences(SGUID refGuid, SGUID refGoBack, const char* szItemName, const TScriptFile* pFile, bool searchInAllFiles)
203 // Check if the refGuid is actually a action and assign the proper search guid
204 if (const IScriptActionInstance* pAction = pFile->GetActionInstance(refGuid))
206 refGuid = pAction->GetActionGUID();
209 if (searchInAllFiles)
211 auto visitFiles = [refGuid, refGoBack, szItemName](const TScriptFile& file)->EVisitStatus
213 SReferencesLogInfo refInfo;
214 FindReferences(refGuid, refGoBack, szItemName, &file, refInfo);
215 if (!refInfo.IsEmpty())
217 PrintReferencesToSchematycConsole(refInfo);
219 return EVisitStatus::Continue;
222 GetSchematyc()->GetScriptRegistry().VisitFiles(TScriptFileConstVisitor::FromLambdaFunction(visitFiles));
224 else
226 SReferencesLogInfo refInfo;
227 FindReferences(refGuid, refGoBack, szItemName, pFile, refInfo);
228 PrintReferencesToSchematycConsole(refInfo);
232 } // namespace LibUtils
234 } // namespace Schematyc