Kactus2
Kactus2 reference guide
Loading...
Searching...
No Matches
PythonAPI.cpp
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// File: PythonAPI.cpp
3//-----------------------------------------------------------------------------
4// Project: Kactus 2
5// Author: Mikko Teuho
6// Date: 12.02.2020
7//
8// Description:
9// Interface for accessing Kactus2 data using Python.
10//-----------------------------------------------------------------------------
11
12#include "PythonAPI.h"
13
14
15#include <KactusAPI/KactusAPI.h>
16
20
22
39
40#include <IPXACTmodels/common/ConfigurableVLNVReference.h>
41#include <IPXACTmodels/common/validators/ParameterValidator.h>
42
43#include <IPXACTmodels/Component/Component.h>
44#include <IPXACTmodels/Component/Port.h>
45#include <IPXACTmodels/Component/View.h>
46#include <IPXACTmodels/Component/MemoryMap.h>
47#include <IPXACTmodels/Component/PortMap.h>
48#include <IPXACTmodels/Component/AddressBlock.h>
49#include <IPXACTmodels/Component/MemoryBlockBase.h>
50#include <IPXACTmodels/Component/RegisterBase.h>
51#include <IPXACTmodels/Component/Register.h>
52#include <IPXACTmodels/Component/Field.h>
53#include <IPXACTmodels/Component/validators/FieldValidator.h>
54#include <IPXACTmodels/Component/validators/EnumeratedValueValidator.h>
55#include <IPXACTmodels/Component/validators/RegisterValidator.h>
56#include <IPXACTmodels/Component/validators/RegisterFileValidator.h>
57#include <IPXACTmodels/Component/validators/AddressBlockValidator.h>
58#include <IPXACTmodels/Component/validators/SubspaceMapValidator.h>
59#include <IPXACTmodels/Component/validators/MemoryMapValidator.h>
60#include <IPXACTmodels/Component/validators/FileSetValidator.h>
61#include <IPXACTmodels/Component/validators/FileValidator.h>
62
63#include <IPXACTmodels/Design/Interconnection.h>
64#include <IPXACTmodels/Design/AdHocConnection.h>
65#include <IPXACTmodels/Design/ActiveInterface.h>
66#include <IPXACTmodels/Design/Design.h>
67
68
69#include <IPXACTmodels/DesignConfiguration/DesignConfiguration.h>
70
71//-----------------------------------------------------------------------------
72// Function: PythonAPI::PythonAPI()
73//-----------------------------------------------------------------------------
75{
76 constructMemoryValidators();
77 constructMemoryInterface();
78 constructFileSetInterface();
79}
80
81//-----------------------------------------------------------------------------
82// Function: PythonAPI::setupLibrary()
83//-----------------------------------------------------------------------------
84void PythonAPI::setupLibrary(std::string const& /*settingsFileString*/)
85{
86 library_->searchForIPXactFiles();
87}
88
89//-----------------------------------------------------------------------------
90// Function: PythonAPI::getVersion()
91//-----------------------------------------------------------------------------
92std::string PythonAPI::getVersion() const
93{
94 return KactusAPI::getVersion().toStdString();
95}
96
97//-----------------------------------------------------------------------------
98// Function: PythonAPI::getLibraryPaths()
99//-----------------------------------------------------------------------------
100std::vector<std::string> PythonAPI::getAllLibraryPaths() const
101{
102 QStringList locations = KactusAPI::getAllLibraryPaths();
103
104 std::vector<std::string> paths;
105 for (auto const& path : locations)
106 {
107 paths.push_back(path.toStdString());
108 }
109
110 return paths;
111}
112
113//-----------------------------------------------------------------------------
114// Function: PythonAPI::setLibraryPathActive()
115//-----------------------------------------------------------------------------
116void PythonAPI::setLibraryPathActive(std::string const& path, bool isActive)
117{
118 KactusAPI::setLibraryPathActive(QString::fromStdString(path), isActive);
119}
120
121//-----------------------------------------------------------------------------
122// Function: PythonAPI::addLibraryPath()
123//-----------------------------------------------------------------------------
124void PythonAPI::addLibraryPath(std::string const& path, bool isActive /*= true*/)
125{
126 KactusAPI::addLibraryPath(QString::fromStdString(path), isActive);
127}
128
129//-----------------------------------------------------------------------------
130// Function: PythonAPI::removeLibraryPath()
131//-----------------------------------------------------------------------------
132void PythonAPI::removeLibraryPath(std::string const& path)
133{
134 if (KactusAPI::removeLibraryPath(QString::fromStdString(path)) == false)
135 {
136 messager_->showError(QStringLiteral("Error: Cannot remove default library path"));
137 }
138}
139
140//-----------------------------------------------------------------------------
141// Function: PythonAPI::getActiveLibraryPaths()
142//-----------------------------------------------------------------------------
143std::vector<std::string> PythonAPI::getActiveLibraryPaths() const
144{
145 QStringList locations = KactusAPI::getActiveLibraryPaths();
146
147 std::vector<std::string> paths;
148 for (auto const& path : locations)
149 {
150 paths.push_back(path.toStdString());
151 }
152
153 return paths;
154}
155
156//-----------------------------------------------------------------------------
157// Function: PythonAPI::getPortsInterface()
158//-----------------------------------------------------------------------------
160{
161 return portsInterface_;
162}
163
164//-----------------------------------------------------------------------------
165// Function: PythonAPI::getComponentParameterInterface()
166//-----------------------------------------------------------------------------
168{
169 return componentParameterInterface_;
170}
171
172//-----------------------------------------------------------------------------
173// Function: PythonAPI::getMapInterface()
174//-----------------------------------------------------------------------------
176{
177 return mapInterface_;
178}
179
180//-----------------------------------------------------------------------------
181// Function: PythonAPI::getFileSetInterface()
182//-----------------------------------------------------------------------------
184{
185 return fileSetInterface_;
186}
187
188//-----------------------------------------------------------------------------
189// Function: PythonAPI::getBusInterface()
190//-----------------------------------------------------------------------------
192{
193 return busInterface_;
194}
195
196//-----------------------------------------------------------------------------
197// Function: PythonAPI::setLibraryPaths()
198//-----------------------------------------------------------------------------
199void PythonAPI::setLibraryPaths(std::vector<std::string> const& paths) const
200{
201 QStringList libraryPaths;
202 for (auto const& path : paths)
203 {
204 libraryPaths.append(QString::fromStdString(path));
205 }
206
207 KactusAPI::setLibraryPaths(libraryPaths);
208}
209
210//-----------------------------------------------------------------------------
211// Function: PythonAPI::getDefaultLibraryPath()
212//-----------------------------------------------------------------------------
214{
215 return KactusAPI::getDefaultLibraryPath().toStdString();
216}
217
218//-----------------------------------------------------------------------------
219// Function: PythonAPI::setDefaultLibraryPath()
220//-----------------------------------------------------------------------------
221void PythonAPI::setDefaultLibraryPath(std::string const& path) const
222{
223 KactusAPI::setDefaultLibraryPath(QString::fromStdString(path));
224}
225
226//-----------------------------------------------------------------------------
227// Function: PythonAPI::setDefaultLibraryPath()
228//-----------------------------------------------------------------------------
229int PythonAPI::importFile(std::string const& path, std::string const& vlnv, bool overwrite /*= false*/) const
230{
231 VLNV targetVLNV(VLNV::COMPONENT, QString::fromStdString(vlnv));
232
233 return KactusAPI::importFile(QString::fromStdString(path), targetVLNV, overwrite);
234}
235
236//-----------------------------------------------------------------------------
237// Function: PythonAPI::generate()
238//-----------------------------------------------------------------------------
239void PythonAPI::generate(std::string const& format, std::string const& vlnv, std::string const& viewName,
240 std::string const& outputDirectory) const
241{
242 VLNV componentVLNV(VLNV::COMPONENT, QString::fromStdString(vlnv));
243 KactusAttribute::Implementation implementation = KactusAttribute::HW;
244
245 QString fileFormat = QString::fromStdString(format).toLower();
246
247 QStringList availableFormats;
248
249 IGeneratorPlugin* generator = nullptr;
250 for (auto plugin : KactusAPI::getPlugins())
251 {
252 CLIGenerator* runnable = dynamic_cast<CLIGenerator*>(plugin);
253 if (runnable != 0)
254 {
255 if (runnable->getOutputFormat().toLower() == fileFormat)
256 {
257 generator = dynamic_cast<IGeneratorPlugin*>(plugin);
258 }
259
260 availableFormats.append(runnable->getOutputFormat());
261 }
262 }
263
264 if (generator != nullptr)
265 {
266 KactusAPI::runGenerator(generator, componentVLNV, QString::fromStdString(viewName),
267 QString::fromStdString(outputDirectory), implementation, nullptr);
268 }
269 else
270 {
271 availableFormats.sort(Qt::CaseInsensitive);
272 messager_->showError(QStringLiteral("No generator found for format %1. Available options are: %2").arg(
273 fileFormat, availableFormats.join(',')));
274 }
275}
276
277//-----------------------------------------------------------------------------
278// Function: PythonAPI::generateInterconnect()
279//-----------------------------------------------------------------------------
281{
282
283 auto interconGen = InterconnectGeneration::Generator(library_, messager_);
284
285 VLNV interconVLNV = interconGen.generate();
286}
287
288//-----------------------------------------------------------------------------
289// Function: PythonAPI::getFileCount()
290//-----------------------------------------------------------------------------
292{
293 return library_->getAllVLNVs().count();
294}
295
296//-----------------------------------------------------------------------------
297// Function: PythonAPI::listVLNVs()
298//-----------------------------------------------------------------------------
299std::vector<std::string> PythonAPI::listVLNVs(std::string const& vendor) const
300{
301 std::vector<std::string> vlnvStrings;
302
303 for (auto const& itemVLNV : library_->getAllVLNVs())
304 {
305 vlnvStrings.push_back(itemVLNV.toString().toStdString());
306 }
307
308 return vlnvStrings;
309}
310
311//-----------------------------------------------------------------------------
312// Function: PythonAPI::listComponentVLNVs()
313//-----------------------------------------------------------------------------
314std::vector<std::string> PythonAPI::listComponentVLNVs() const
315{
316 std::vector<std::string> componentVLNVs;
317
318 for (auto const& itemVLNV : library_->getAllVLNVs())
319 {
320 if (itemVLNV.getType() == VLNV::COMPONENT)
321 {
322 componentVLNVs.push_back(itemVLNV.toString().toStdString());
323 }
324 }
325
326 return componentVLNVs;
327}
328
329//-----------------------------------------------------------------------------
330// Function: PythonAPI::vlnvExistsInLibrary()
331//-----------------------------------------------------------------------------
332bool PythonAPI::vlnvExistsInLibrary(std::string const& vendor, std::string const& library, std::string const& name,
333 std::string const& version) const
334{
335 if (vendor.empty() || library.empty() || name.empty() || version.empty())
336 {
337 messager_->showError("Error in given VLNV.");
338 return false;
339 }
340
341 return library_->contains(VLNV(VLNV::INVALID,
342 QString::fromStdString(vendor),
343 QString::fromStdString(library),
344 QString::fromStdString(name),
345 QString::fromStdString(version)));
346}
347
348//-----------------------------------------------------------------------------
349// Function: PythonAPI::createComponent()
350//-----------------------------------------------------------------------------
351bool PythonAPI::createComponent(std::string const& vendor, std::string const& library, std::string const& name,
352 std::string const& version, StdRev revision /*= StdRev::Std22*/)
353{
354 if (vendor.empty() || library.empty() || name.empty() || version.empty())
355 {
356 messager_->showError("Error in given VLNV.");
357 return false;
358 }
359
360 VLNV newComponentVLNV;
361 newComponentVLNV.setVendor(QString::fromStdString(vendor));
362 newComponentVLNV.setLibrary(QString::fromStdString(library));
363 newComponentVLNV.setName(QString::fromStdString(name));
364 newComponentVLNV.setVersion(QString::fromStdString(version));
365 newComponentVLNV.setType(VLNV::COMPONENT);
366
367 if (library_->contains(newComponentVLNV))
368 {
369 return false;
370 }
371
372 Document::Revision docRevision = revision == PythonAPI::StdRev::Std22
373 ? Document::Revision::Std22 : Document::Revision::Std14;
374
375 QSharedPointer<Component> component = QSharedPointer<Component>(new Component(newComponentVLNV, docRevision));
376
377 component->setHierarchy(KactusAttribute::FLAT);
378 component->setFirmness(KactusAttribute::MUTABLE);
379 component->setImplementation(KactusAttribute::HW);
380 component->setVersion(KactusAPI::getVersionFileString());
381
382 QString directory = KactusAPI::getDefaultLibraryPath();
383 QString vlnvDir = "/" + newComponentVLNV.getVendor() + "/" + newComponentVLNV.getLibrary() + "/" +
384 newComponentVLNV.getName() + "/" + newComponentVLNV.getVersion();
385
386 directory += vlnvDir;
387
388 if (!library_->writeModelToFile(directory, component))
389 {
390 messager_->showError("Error saving file to disk.");
391 return false;
392 }
393
394 openComponent(newComponentVLNV.toString().toStdString());
395
396 return true;
397}
398
399//-----------------------------------------------------------------------------
400// Function: PythonAPI::getVLNVDirectory()
401//-----------------------------------------------------------------------------
402std::string PythonAPI::getVLNVDirectory(std::string const& vendor, std::string const& library,
403 std::string const& name, std::string const& version) const
404{
405 VLNV documentVLNV;
406 documentVLNV.setVendor(QString::fromStdString(vendor));
407 documentVLNV.setLibrary(QString::fromStdString(library));
408 documentVLNV.setName(QString::fromStdString(name));
409 documentVLNV.setVersion(QString::fromStdString(version));
410
411 return KactusAPI::getDocumentFilePath(documentVLNV).toStdString();
412}
413
414//-----------------------------------------------------------------------------
415// Function: PythonAPI::getFirstViewName()
416//-----------------------------------------------------------------------------
418{
419 if (activeComponent_)
420 {
421 QStringList componentNames = activeComponent_->getViewNames();
422 if (!componentNames.isEmpty())
423 {
424 return componentNames.first().toStdString();
425 }
426 else
427 {
428 QSharedPointer<View> newView(new View("mockView"));
429 activeComponent_->getViews()->append(newView);
430 return newView->name().toStdString();
431 }
432 }
433
434 return std::string();
435}
436
437//-----------------------------------------------------------------------------
438// Function: PythonAPI::openComponent()
439//-----------------------------------------------------------------------------
440bool PythonAPI::openComponent(std::string const& vlnvString)
441{
442 QString componentVLNV = QString::fromStdString(vlnvString);
443 QSharedPointer<Document> componentDocument = getDocument(componentVLNV);
444 if (componentDocument)
445 {
446 QSharedPointer<Component> component = componentDocument.dynamicCast<Component>();
447 if (component)
448 {
449 parameterFinder_->setComponent(component);
450 portValidator_->componentChange(component->getViews());
451 portsInterface_->setPorts(component->getPorts());
452
453 parameterValidator_->componentChange(component->getChoices(), component->getRevision());
454 componentParameterInterface_->setParameters(component->getParameters());
455 componentParameterInterface_->setChoices(component->getChoices());
456
457 mapValidator_->componentChange(component);
458 mapInterface_->setMemoryMaps(component);
459
460 fileSetInterface_->setFileSets(component->getFileSets());
461
462 busInterface_->setBusInterfaces(component);
463
464 activeComponent_ = component;
465 messager_->showMessage(QString("Component %1 is open").arg(componentVLNV));
466 return true;
467 }
468 else
469 {
470 messager_->showError(QString("The given VLNV %1 is not a component").arg(componentVLNV));
471 return false;
472 }
473 }
474 else
475 {
476 messager_->showError(QString("Could not open document with VLNV %1").arg(componentVLNV));
477 return false;
478 }
479}
480
481//-----------------------------------------------------------------------------
482// Function: PythonAPI::getDocument()
483//-----------------------------------------------------------------------------
484QSharedPointer<Document> PythonAPI::getDocument(QString const& vlnvString) const
485{
486 QStringList vlnvArray = vlnvString.split(':');
487 if (vlnvArray.size() != 4)
488 {
489 messager_->showError(QString("The given VLNV %1 is not valid").arg(vlnvString));
490 return QSharedPointer<Document>();
491 }
492
493 VLNV targetVLNV(VLNV::COMPONENT, vlnvArray.at(0), vlnvArray.at(1), vlnvArray.at(2), vlnvArray.at(3));
494 return library_->getModel(targetVLNV);
495}
496
497//-----------------------------------------------------------------------------
498// Function: PythonAPI::closeOpenComponent()
499//-----------------------------------------------------------------------------
501{
502 if (activeComponent_)
503 {
504 messager_->showMessage(QString("Component %1 is closed").arg(activeComponent_->getVlnv().toString()));
505 }
506
507 activeComponent_ = QSharedPointer<Component>();
508}
509
510//-----------------------------------------------------------------------------
511// Function: PythonAPI::getComponentName()
512//-----------------------------------------------------------------------------
514{
515 if (activeComponent_)
516 {
517 return activeComponent_->getVlnv().getName().toStdString();
518 }
519 else
520 {
521 return std::string();
522 }
523}
524
525//-----------------------------------------------------------------------------
526// Function: PythonAPI::getComponentDescription()
527//-----------------------------------------------------------------------------
529{
530 if (activeComponent_)
531 {
532 return activeComponent_->getDescription().toStdString();
533 }
534 else
535 {
536 return std::string();
537 }
538}
539
540//-----------------------------------------------------------------------------
541// Function: PythonAPI::getComponentStdRevision()
542//-----------------------------------------------------------------------------
544{
545 if (activeComponent_)
546 {
547 return Document::toStdString(activeComponent_->getRevision());
548 }
549
550 return std::string();
551}
552
553//-----------------------------------------------------------------------------
554// Function: PythonAPI::saveComponent()
555//-----------------------------------------------------------------------------
557{
558 if (activeComponent_)
559 {
560 messager_->showMessage(QString("Saving component %1 ...").arg(activeComponent_->getVlnv().toString()));
561
562
563 if (library_->writeModelToFile(activeComponent_))
564 {
565 messager_->showMessage(QString("Save complete"));
566 }
567 else
568 {
569 messager_->showError(QString("Could not save component %1").arg(activeComponent_->getVlnv().toString()));
570 }
571 }
572}
573
574
575//-----------------------------------------------------------------------------
576// Function: PythonAPI::constructMemoryValidators()
577//-----------------------------------------------------------------------------
578void PythonAPI::constructMemoryValidators()
579{
580 QSharedPointer<EnumeratedValueValidator> enumValidator(new EnumeratedValueValidator(expressionParser_));
581 QSharedPointer<FieldValidator>fieldValidator(new FieldValidator(
582 expressionParser_, enumValidator, parameterValidator_));
583 QSharedPointer<RegisterValidator> registerValidator (new RegisterValidator(
584 expressionParser_, fieldValidator, parameterValidator_));
585 QSharedPointer<RegisterFileValidator> registerFileValidator(
586 new RegisterFileValidator(expressionParser_, registerValidator, parameterValidator_,
587 Document::Revision::Unknown));
588
589 QSharedPointer<AddressBlockValidator> blockValidator(new AddressBlockValidator(
590 expressionParser_, registerValidator, registerFileValidator, parameterValidator_,
591 Document::Revision::Unknown));
592
593 QSharedPointer<SubspaceMapValidator> subspaceValidator(
594 new SubspaceMapValidator(expressionParser_, parameterValidator_, Document::Revision::Unknown));
595
596 QSharedPointer<MemoryMapValidator> mapValidator(
597 new MemoryMapValidator(expressionParser_, blockValidator, subspaceValidator, QSharedPointer<Component>()));
598
599 mapValidator_ = mapValidator;
600}
601
602//-----------------------------------------------------------------------------
603// Function: PythonAPI::constructMemoryInterface()
604//-----------------------------------------------------------------------------
605void PythonAPI::constructMemoryInterface()
606{
607 QSharedPointer<SubspaceMapValidator> subspaceValidator = mapValidator_->getSubspaceValidator();
608 QSharedPointer<AddressBlockValidator> blockValidator = mapValidator_->getAddressBlockValidator();
609 QSharedPointer<RegisterValidator> registerValidator = blockValidator->getRegisterValidator();
610 QSharedPointer<FieldValidator> fieldValidator = registerValidator->getFieldValidator();
611
612 ResetInterface* resetInterface(new ResetInterface(fieldValidator, expressionParser_, expressionFormatter_));
613 FieldInterface* fieldInterface(
614 new FieldInterface(fieldValidator, expressionParser_, expressionFormatter_, resetInterface));
615
616 ModeReferenceInterface* modeReferenceInterface(new ModeReferenceInterface());
617
618 AccessPolicyInterface* accessPolicyInterface(new AccessPolicyInterface(modeReferenceInterface));
619
620 RegisterInterface* registerInterface(
621 new RegisterInterface(registerValidator, expressionParser_, expressionFormatter_, fieldInterface,
622 accessPolicyInterface));
623
624 AddressBlockInterface* blockInterface(new AddressBlockInterface(blockValidator, expressionParser_,
625 expressionFormatter_, busInterface_, registerInterface, componentParameterInterface_));
626 SubspaceMapInterface* subspaceInterface(new SubspaceMapInterface(
627 subspaceValidator, expressionParser_, expressionFormatter_, busInterface_, componentParameterInterface_));
628
629 mapInterface_ = new MemoryMapInterface(mapValidator_, expressionParser_, expressionFormatter_);
630
631 mapInterface_->setAddressBlockInterface(blockInterface);
632 mapInterface_->setSubspaceMapInterface(subspaceInterface);
633 mapInterface_->setModeReferenceInterface(modeReferenceInterface);
634}
635
636//-----------------------------------------------------------------------------
637// Function: PythonAPI::setBlocksForInterface()
638//-----------------------------------------------------------------------------
639void PythonAPI::setBlocksForInterface(std::string const& mapName)
640{
641 AddressBlockInterface* blockInterface = mapInterface_->getAddressBlockInterface();
642
643 QString mapNameQT = QString::fromStdString(mapName);
644 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
645 if (!containingMap)
646 {
647 sendMemoryMapNotFoundError(mapNameQT);
648 return;
649 }
650
651 blockInterface->setMemoryBlocks(containingMap->getMemoryBlocks());
652 blockInterface->setAddressUnitBits(containingMap->getAddressUnitBits().toStdString());
653}
654
655//-----------------------------------------------------------------------------
656// Function: PythonAPI::setRegistersForInterface()
657//-----------------------------------------------------------------------------
658void PythonAPI::setRegistersForInterface(std::string const& mapName, std::string const& blockName)
659{
660 RegisterInterface* interfacePointer = mapInterface_->getAddressBlockInterface()->getSubInterface();
661
662 QString mapNameQT = QString::fromStdString(mapName);
663 QString blockNameQT = QString::fromStdString(blockName);
664
665 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
666 if (containingMap)
667 {
668 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
669 if (containingBlock)
670 {
671 interfacePointer->setRegisters(containingBlock->getRegisterData());
672 interfacePointer->setAddressUnitBits(
673 expressionParser_->parseExpression(containingMap->getAddressUnitBits()).toInt());
674 }
675 else
676 {
677 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
678 }
679 }
680 else
681 {
682 sendMemoryMapNotFoundError(mapNameQT);
683 }
684}
685
686//-----------------------------------------------------------------------------
687// Function: PythonAPI::setFieldsForInterface()
688//-----------------------------------------------------------------------------
689void PythonAPI::setFieldsForInterface(std::string const& mapName, std::string const& blockName,
690 std::string const& registerName)
691{
692 FieldInterface* interfacePointer =
693 mapInterface_->getAddressBlockInterface()->getSubInterface()->getSubInterface();
694
695 QString mapNameQT = QString::fromStdString(mapName);
696 QString blockNameQT = QString::fromStdString(blockName);
697 QString registerNameQT = QString::fromStdString(registerName);
698
699 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
700 if (containingMap)
701 {
702 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
703 if (containingBlock)
704 {
705 QSharedPointer<Register> containingRegister = getRegister(containingBlock, registerNameQT);
706 if (containingRegister)
707 {
708 interfacePointer->setFields(containingRegister->getFields());
709 }
710 else
711 {
712 sendRegisterNotFoundError(mapNameQT, blockNameQT, registerNameQT);
713 }
714 }
715 else
716 {
717 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
718 }
719 }
720 else
721 {
722 sendMemoryMapNotFoundError(mapNameQT);
723 }
724}
725
726//-----------------------------------------------------------------------------
727// Function: PythonAPI::setResetsForInterface()
728//-----------------------------------------------------------------------------
729void PythonAPI::setResetsForInterface(std::string const& mapName, std::string const& blockName,
730 std::string const& registerName, std::string const& fieldName)
731{
732 ResetInterface* interfacePointer =
733 mapInterface_->getAddressBlockInterface()->getSubInterface()->getSubInterface()->getSubInterface();
734
735 QString mapNameQT = QString::fromStdString(mapName);
736 QString blockNameQT = QString::fromStdString(blockName);
737 QString registerNameQT = QString::fromStdString(registerName);
738 QString fieldNameQT = QString::fromStdString(fieldName);
739
740 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
741 if (containingMap)
742 {
743 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
744 if (containingBlock)
745 {
746 QSharedPointer<Register> containingRegister = getRegister(containingBlock, registerNameQT);
747 if (containingRegister)
748 {
749 QSharedPointer<Field> containingField = getField(containingRegister, fieldNameQT);
750 if (containingField)
751 {
752 interfacePointer->setResets(containingField);
753 }
754 else
755 {
756 sendFieldNotFoundError(mapNameQT, blockNameQT, registerNameQT, fieldNameQT);
757 }
758 }
759 else
760 {
761 sendRegisterNotFoundError(mapNameQT, blockNameQT, registerNameQT);
762 }
763 }
764 else
765 {
766 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
767 }
768 }
769 else
770 {
771 sendMemoryMapNotFoundError(mapNameQT);
772 }
773}
774
775//-----------------------------------------------------------------------------
776// Function: PythonAPI::getMemoryMap()
777//-----------------------------------------------------------------------------
778QSharedPointer<MemoryMap> PythonAPI::getMemoryMap(QString const& mapName) const
779{
780 for (auto map : *activeComponent_->getMemoryMaps())
781 {
782 if (map->name() == mapName)
783 {
784 return map;
785 }
786 }
787
788 return QSharedPointer<MemoryMap>();
789}
790
791//-----------------------------------------------------------------------------
792// Function: PythonAPI::getAddressBock()
793//-----------------------------------------------------------------------------
794QSharedPointer<AddressBlock> PythonAPI::getAddressBock(QSharedPointer<MemoryMap> containingMap,
795 QString const& blockName) const
796{
797 for (auto baseBlock : *containingMap->getMemoryBlocks())
798 {
799 QSharedPointer<AddressBlock> block = baseBlock.dynamicCast<AddressBlock>();
800 if (block && block->name() == blockName)
801 {
802 return block;
803 }
804 }
805
806 return QSharedPointer<AddressBlock>();
807}
808
809//-----------------------------------------------------------------------------
810// Function: PythonAPI::getRegister()
811//-----------------------------------------------------------------------------
812QSharedPointer<Register> PythonAPI::getRegister(QSharedPointer<AddressBlock> containingBlock,
813 QString const& registerName) const
814{
815 for (auto baseRegister : *containingBlock->getRegisterData())
816 {
817 QSharedPointer<Register> currentRegister = baseRegister.dynamicCast<Register>();
818 if (currentRegister && currentRegister->name() == registerName)
819 {
820 return currentRegister;
821 }
822 }
823
824 return QSharedPointer<Register>();
825}
826
827//-----------------------------------------------------------------------------
828// Function: PythonAPI::getField()
829//-----------------------------------------------------------------------------
830QSharedPointer<Field> PythonAPI::getField(QSharedPointer<Register> containingRegister, QString const& fieldName)
831 const
832{
833 for (auto currentField : *containingRegister->getFields())
834 {
835 if (currentField->name() == fieldName)
836 {
837 return currentField;
838 }
839 }
840
841 return QSharedPointer<Field>();
842}
843
844//-----------------------------------------------------------------------------
845// Function: PythonAPI::constructFileSetInterface()
846//-----------------------------------------------------------------------------
847void PythonAPI::constructFileSetInterface()
848{
849 QSharedPointer<FileValidator> newFileValidator(new FileValidator(expressionParser_));
850 QSharedPointer<FileSetValidator> newFileSetValidator(
851 new FileSetValidator(newFileValidator, expressionParser_));
852
853 FileInterface* fileInterface = new FileInterface(newFileValidator, expressionParser_, expressionFormatter_);
854
855 FileBuilderInterface* fileBuilderInterface = new FileBuilderInterface(expressionParser_, expressionFormatter_);
856
857 fileSetInterface_ = new FileSetInterface(
858 newFileSetValidator, expressionParser_, expressionFormatter_, fileInterface, fileBuilderInterface);
859}
860
861//-----------------------------------------------------------------------------
862// Function: PythonAPI::setFilesForInterface()
863//-----------------------------------------------------------------------------
864void PythonAPI::setFilesForInterface(std::string const& setName)
865{
866 FileInterface* fileInterface = fileSetInterface_->getFileInterface();
867
868 QString fileSetNameQT = QString::fromStdString(setName);
869 QSharedPointer<FileSet> containingFileSet = getFileSet(fileSetNameQT);
870 if (!containingFileSet)
871 {
872 sendFileSetNotFoundError(fileSetNameQT);
873 return;
874 }
875
876 fileInterface->setFiles(containingFileSet->getFiles());
877}
878
879//-----------------------------------------------------------------------------
880// Function: PythonAPI::getFileSet()
881//-----------------------------------------------------------------------------
882QSharedPointer<FileSet> PythonAPI::getFileSet(QString const& setName) const
883{
884 for (auto fileSet : *activeComponent_->getFileSets())
885 {
886 if (fileSet->name() == setName)
887 {
888 return fileSet;
889 }
890 }
891
892 return QSharedPointer<FileSet>();
893}
894
895//-----------------------------------------------------------------------------
896// Function: PythonAPI::setFileBuildersForInterface()
897//-----------------------------------------------------------------------------
898void PythonAPI::setFileBuildersForInterface(std::string const& setName)
899{
900 FileBuilderInterface* builderInterface = fileSetInterface_->getFileBuilderInterface();
901
902 QString fileSetNameQT = QString::fromStdString(setName);
903 QSharedPointer<FileSet> containingFileSet = getFileSet(fileSetNameQT);
904 if (!containingFileSet)
905 {
906 sendFileSetNotFoundError(fileSetNameQT);
907 return;
908 }
909
910 builderInterface->setFileBuilders(containingFileSet->getDefaultFileBuilders());
911}
912
913//-----------------------------------------------------------------------------
914// Function: PythonAPI::createDesign()
915//-----------------------------------------------------------------------------
916bool PythonAPI::createDesign(std::string const& vendor, std::string const& library,
917 std::string const& name, std::string const& version, StdRev revision /*= StdRev::Std22*/)
918{
919 if (vendor.empty() || library.empty() || name.empty() || version.empty())
920 {
921 messager_->showError("Error in given VLNV.");
922 return false;
923 }
924
925 VLNV componentVLNV(VLNV::DESIGN,
926 QString::fromStdString(vendor),
927 QString::fromStdString(library),
928 QString::fromStdString(name),
929 QString::fromStdString(version));
930
931 if (createComponent(vendor, library, name, version, revision) == false)
932 {
933 messager_->showError("Error in creating containing component.");
934 return false;
935 }
936
937 VLNV designVLNV(VLNV::DESIGN, componentVLNV.getVendor(), componentVLNV.getLibrary(),
938 componentVLNV.getName() + ".design", componentVLNV.getVersion());
939 VLNV desConfVLNV(VLNV::DESIGNCONFIGURATION, componentVLNV.getVendor(), componentVLNV.getLibrary(),
940 componentVLNV.getName()+ ".designcfg", componentVLNV.getVersion());
941
942 if (library_->contains(designVLNV))
943 {
944 return false;
945 }
946
947 QSharedPointer<DesignConfigurationInstantiation> hierarchicalInstantiation
948 (new DesignConfigurationInstantiation(desConfVLNV.getName() + "_" + desConfVLNV.getVersion()));
949
950 QSharedPointer<ConfigurableVLNVReference> tempReference(new ConfigurableVLNVReference(desConfVLNV));
951 hierarchicalInstantiation->setDesignConfigurationReference(tempReference);
952
953 QSharedPointer<View> newHierarchicalView(new View(QStringLiteral("hierarchical")));
954 newHierarchicalView->setDesignConfigurationInstantiationRef(hierarchicalInstantiation->name());
955
956 activeComponent_->getDesignConfigurationInstantiations()->append(hierarchicalInstantiation);
957 activeComponent_->getViews()->append(newHierarchicalView);
958
959 auto design = QSharedPointer<Design>(new Design(designVLNV, Document::Revision::Std14));
960 design->setVersion(KactusAPI::getVersionFileString());
961 design->setDesignImplementation(KactusAttribute::HW);
962
963
964 auto designConf = QSharedPointer<DesignConfiguration>(new DesignConfiguration(desConfVLNV, Document::Revision::Std14));
965 designConf->setDesignRef(designVLNV);
966 designConf->setDesignConfigImplementation(KactusAttribute::HW);
967 designConf->setVersion(KactusAPI::getVersionFileString());
968
969 if (QString directory = KactusAPI::getDefaultLibraryPath() + "/" + designVLNV.toString(QStringLiteral("/"));
970 !library_->writeModelToFile(activeComponent_) ||
971 !library_->writeModelToFile(directory, design) ||
972 !library_->writeModelToFile(directory, designConf))
973 {
974 messager_->showError("Error saving file to disk.");
975 return false;
976 }
977
978 openDesign(designVLNV.toString().toStdString());
979
980 return true;
981}
982
983//-----------------------------------------------------------------------------
984// Function: PythonAPI::getDesignStdRevision()
985//-----------------------------------------------------------------------------
987{
988 if (activeDesign_)
989 {
990 return Document::toStdString(activeDesign_->getRevision());
991 }
992
993 return std::string();
994}
995
996//-----------------------------------------------------------------------------
997// Function: PythonAPI::sendMemoryMapNotFoundError()
998//-----------------------------------------------------------------------------
999void PythonAPI::sendMemoryMapNotFoundError(QString const& mapName) const
1000{
1001 messager_->showError(QString("Could not find memory map %1 within component %2").
1002 arg(mapName, activeComponent_->getVlnv().toString()));
1003}
1004
1005//-----------------------------------------------------------------------------
1006// Function: PythonAPI::sendAddressBlockNotFoundError()
1007//-----------------------------------------------------------------------------
1008void PythonAPI::sendAddressBlockNotFoundError(QString const& mapName, QString const& blockName) const
1009{
1010 messager_->showError(QString("Could not find address block %1 within memory map %2 in component %3").
1011 arg(blockName, mapName, activeComponent_->getVlnv().toString()));
1012}
1013
1014//-----------------------------------------------------------------------------
1015// Function: PythonAPI::sendRegisterNotFoundError()
1016//-----------------------------------------------------------------------------
1017void PythonAPI::sendRegisterNotFoundError(QString const& mapName, QString const& blockName,
1018 QString const& registerName) const
1019{
1020 messager_->showError(
1021 QString("Could not find register %1 within address block %2 in memory map %3 in component %4").
1022 arg(registerName, blockName, mapName, activeComponent_->getVlnv().toString()));
1023}
1024
1025//-----------------------------------------------------------------------------
1026// Function: PythonAPI::sendFieldNotFoundError()
1027//-----------------------------------------------------------------------------
1028void PythonAPI::sendFieldNotFoundError(QString const& mapName, QString const& blockName,
1029 QString const& registerName, QString const& fieldName) const
1030{
1031 messager_->showError(
1032 QString("Could not find field %1 within register %2 in address block %3 in memory map %4 in component %5").
1033 arg(fieldName, registerName, blockName, mapName, activeComponent_->getVlnv().toString()));
1034}
1035
1036//-----------------------------------------------------------------------------
1037// Function: PythonAPI::sendFileSetNotFoundError()
1038//-----------------------------------------------------------------------------
1039void PythonAPI::sendFileSetNotFoundError(QString const& setName) const
1040{
1041 messager_->showError(QString("Could not find file set %1 within component %2").
1042 arg(setName, activeComponent_->getVlnv().toString()));
1043}
1044
1045//-----------------------------------------------------------------------------
1046// Function: PythonAPI::openDesign()
1047//-----------------------------------------------------------------------------
1048bool PythonAPI::openDesign(std::string const& vlnvString)
1049{
1050 QString designVLNV = QString::fromStdString(vlnvString);
1051 QSharedPointer<Document> designDocument = getDocument(designVLNV);
1052 if (designDocument)
1053 {
1054 QSharedPointer<Design> design = designDocument.dynamicCast<Design>();
1055 if (design)
1056 {
1057 activeDesign_ = design;
1058 messager_->showMessage(QString("Design %1 is open").arg(designVLNV));
1059
1060 instanceInterface_->setComponentInstances(activeDesign_);
1061 connectionInterface_->setInterconnections(activeDesign_);
1062 adhocConnectionInterface_->setConnections(activeDesign_);
1063
1064 return true;
1065 }
1066 else
1067 {
1068 messager_->showError(QString("The given VLNV %1 is not a design").arg(designVLNV));
1069 return false;
1070 }
1071 }
1072 else
1073 {
1074 messager_->showError(QString("Could not open document with VLNV %1").arg(designVLNV));
1075 return false;
1076 }
1077}
1078
1079//-----------------------------------------------------------------------------
1080// Function: PythonAPI::closeOpenDesign()
1081//-----------------------------------------------------------------------------
1083{
1084 if (activeDesign_)
1085 {
1086 messager_->showMessage(QString("Design %1 is closed").arg(activeDesign_->getVlnv().toString()));
1087 }
1088
1089 activeDesign_ = QSharedPointer<Design>();
1090}
1091
1092//-----------------------------------------------------------------------------
1093// Function: PythonAPI::saveDesign()
1094//-----------------------------------------------------------------------------
1096{
1097 if (activeDesign_)
1098 {
1099 messager_->showMessage(QString("Saving design %1 ...").arg(activeDesign_->getVlnv().toString()));
1100
1101 if (library_->writeModelToFile(activeDesign_))
1102 {
1103 messager_->showMessage(QString("Save complete"));
1104 }
1105 else
1106 {
1107 messager_->showError(QString("Could not save design %1").arg(activeDesign_->getVlnv().toString()));
1108 }
1109 }
1110}
1111
1112//-----------------------------------------------------------------------------
1113// Function: PythonAPI::addComponentInstance()
1114//-----------------------------------------------------------------------------
1115bool PythonAPI::addComponentInstance(std::string const& vlnvString, std::string const& instanceName)
1116{
1117 if (!activeDesign_)
1118 {
1119 messager_->showMessage(QString("No open design"));
1120 return false;
1121 }
1122
1123 QString combinedVLNV = QString::fromStdString(vlnvString);
1124 QSharedPointer<Document> instanceDocument = getDocument(combinedVLNV);
1125 if (!instanceDocument)
1126 {
1127 messager_->showMessage(QString("Could not find document %1").arg(combinedVLNV));
1128 return false;
1129 }
1130
1131 QSharedPointer<Component> instanceComponent = instanceDocument.dynamicCast<Component>();
1132 if (!instanceComponent)
1133 {
1134 messager_->showMessage(QString("%1 is not a component").arg(combinedVLNV));
1135 return false;
1136 }
1137
1138 QStringList vlnvList = combinedVLNV.split(":");
1139 if (vlnvList.size() < 4)
1140 {
1141 messager_->showMessage(QString("The VLNV %1 is not correct").arg(combinedVLNV));
1142 return false;
1143 }
1144
1145 std::string newVendor = vlnvList.at(0).toStdString();
1146 std::string newLibrary = vlnvList.at(1).toStdString();
1147 std::string newName = vlnvList.at(2).toStdString();
1148 std::string newVersion = vlnvList.at(3).toStdString();
1149
1150 instanceInterface_->addComponentInstance(instanceName);
1151 return instanceInterface_->setComponentReference(instanceName, newVendor, newLibrary, newName, newVersion);
1152}
1153
1154//-----------------------------------------------------------------------------
1155// Function: PythonAPI::removeComponentInstance()
1156//-----------------------------------------------------------------------------
1157bool PythonAPI::removeComponentInstance(std::string const& instanceName)
1158{
1159 if (!activeDesign_)
1160 {
1161 messager_->showMessage(QString("No open design"));
1162 return false;
1163 }
1164
1165 return instanceInterface_->removeComponentInstance(instanceName);
1166}
1167
1168//-----------------------------------------------------------------------------
1169// Function: PythonAPI::removeInstanceConnections()
1170//-----------------------------------------------------------------------------
1171bool PythonAPI::removeInstanceConnections(std::string const& instanceName)
1172{
1173 return connectionInterface_->removeInstanceInterconnections(instanceName);
1174}
1175
1176//-----------------------------------------------------------------------------
1177// Function: PythonAPI::removeInstanceAdHocConnections()
1178//-----------------------------------------------------------------------------
1179bool PythonAPI::removeInstanceAdHocConnections(std::string const& instanceName)
1180{
1181 return adhocConnectionInterface_->removeInstanceAdHocConnections(instanceName);
1182}
1183
1184//-----------------------------------------------------------------------------
1185// Function: PythonAPI::renameInstance()
1186//-----------------------------------------------------------------------------
1187bool PythonAPI::renameInstance(std::string const& currentName, std::string const& newName)
1188{
1189 return instanceInterface_->setName(currentName, newName);
1190}
1191
1192//-----------------------------------------------------------------------------
1193// Function: PythonAPI::createConnection()
1194//-----------------------------------------------------------------------------
1195bool PythonAPI::createConnection(std::string const& startInstanceName, std::string const& startBus,
1196 std::string const& endInstanceName, std::string const& endBus)
1197{
1198 QString startInstanceNameQ = QString::fromStdString(startInstanceName);
1199 QString endInstanceNameQ = QString::fromStdString(endInstanceName);
1200 QString startBusNameQ = QString::fromStdString(startBus);
1201 QString endBusNameQ = QString::fromStdString(endBus);
1202
1203 if (!connectionEndsCheck(startInstanceNameQ, startBusNameQ, endInstanceNameQ, endBusNameQ, false))
1204 {
1205 messager_->showMessage(QString("Could not create connection"));
1206 return false;
1207 }
1208
1209 connectionInterface_->addInterconnection(startInstanceName, startBus, endInstanceName, endBus);
1210
1211 return true;
1212}
1213
1214//-----------------------------------------------------------------------------
1215// Function: PythonAPI::createHierarchicalConnection()
1216//-----------------------------------------------------------------------------
1217bool PythonAPI::createHierarchicalConnection(std::string const& instanceName, std::string const& instanceBus,
1218 std::string const& topBus)
1219{
1220 QString instanceNameQ = QString::fromStdString(instanceName);
1221 QString instanceBusNameQ = QString::fromStdString(instanceBus);
1222 QString topBusQ = QString::fromStdString(topBus);
1223
1224 if (!instanceExists(instanceNameQ))
1225 {
1226 messager_->showMessage(QString("Could not create connection"));
1227 return false;
1228 }
1229
1230 connectionInterface_->addHierarchicalInterconnection(instanceName, instanceBus, topBus);
1231
1232 return true;
1233}
1234
1235//-----------------------------------------------------------------------------
1236// Function: PythonAPI::connectionExistenceCheck()
1237//-----------------------------------------------------------------------------
1238bool PythonAPI::connectionEndsCheck(QString const& startInstanceName, QString const& startBus,
1239 QString const& endInstanceName, QString const& endBus, bool isAdHocConnection)
1240{
1241 if (instanceExists(startInstanceName) == false || instanceExists(endInstanceName) == false)
1242 {
1243 return false;
1244 }
1245
1246 QSharedPointer<ConfigurableVLNVReference> startComponenReference =
1247 instanceInterface_->getComponentReference(startInstanceName.toStdString());
1248 QSharedPointer<ConfigurableVLNVReference> endComponentReference =
1249 instanceInterface_->getComponentReference(endInstanceName.toStdString());
1250 QSharedPointer<const Document> startDocument = library_->getModelReadOnly(*startComponenReference.data());
1251 QSharedPointer<const Document> endDocument = library_->getModelReadOnly(*endComponentReference.data());
1252 QSharedPointer<const Component> startComponent = startDocument.dynamicCast<const Component>();
1253 QSharedPointer<const Component> endComponent = endDocument.dynamicCast<const Component>();
1254
1255
1256 if (isAdHocConnection)
1257 {
1258 return endsCheckForAdHoc(
1259 startComponent, startBus, startInstanceName, endComponent, endBus, endInstanceName);
1260 }
1261 else
1262 {
1263 return endsCheckForInterconnection(
1264 startComponent, startBus, startInstanceName, endComponent, endBus, endInstanceName);
1265 }
1266}
1267
1268//-----------------------------------------------------------------------------
1269// Function: PythonAPI::instanceExists()
1270//-----------------------------------------------------------------------------
1271bool PythonAPI::instanceExists(QString const& instanceName) const
1272{
1273 if (!instanceInterface_->instanceExists(instanceName.toStdString()))
1274 {
1275 messager_->showMessage(QString("Could not find component instance %1 within %2").
1276 arg(instanceName, activeDesign_->getVlnv().toString()));
1277 return false;
1278 }
1279
1280 QSharedPointer<ConfigurableVLNVReference> instanceComponenReference =
1281 instanceInterface_->getComponentReference(instanceName.toStdString());
1282
1283 if (!instanceComponenReference)
1284 {
1285 messager_->showMessage(QString("Component instance %1 does not have a component reference").
1286 arg(instanceName));
1287 return false;
1288 }
1289
1290 QSharedPointer<const Document> instanceDocument =
1291 library_->getModelReadOnly(*instanceComponenReference.data());
1292 if (!instanceDocument)
1293 {
1294 messager_->showMessage(QString("Component instance %1 references a non-existing document %2").
1295 arg(instanceName, instanceComponenReference->toString()));
1296 return false;
1297 }
1298
1299 QSharedPointer<const Component> instanceComponent = instanceDocument.dynamicCast<const Component>();
1300 if (!instanceComponent)
1301 {
1302 messager_->showMessage(QString("Component instance %1 component reference %1 is not a component").
1303 arg(instanceName, instanceComponenReference->toString()));
1304 return false;
1305 }
1306
1307 return true;
1308}
1309
1310//-----------------------------------------------------------------------------
1311// Function: PythonAPI::endsCheckForAdHoc()
1312//-----------------------------------------------------------------------------
1313bool PythonAPI::endsCheckForAdHoc(QSharedPointer<const Component> startComponent, QString const& startBus,
1314 QString const& startInstanceName, QSharedPointer<const Component> endComponent, QString const& endBus,
1315 QString const& endInstanceName)
1316{
1317 openComponent(startComponent->getVlnv().toString().toStdString());
1318
1319 DirectionTypes::Direction startDirection =
1320 DirectionTypes::str2Direction(QString::fromStdString(portsInterface_->getDirection(
1321 startBus.toStdString())), DirectionTypes::DIRECTION_INVALID);
1322
1323 if (!portsInterface_->portExists(startBus.toStdString()))
1324 {
1325 messager_->showMessage(QString("Could not find port %1 within component instance %2.").
1326 arg(startBus, startInstanceName));
1327 return false;
1328 }
1329
1330 openComponent(endComponent->getVlnv().toString().toStdString());
1331 DirectionTypes::Direction endDirection = DirectionTypes::str2Direction(QString::fromStdString(
1332 portsInterface_->getDirection(endBus.toStdString())), DirectionTypes::DIRECTION_INVALID);
1333
1334 if (!portsInterface_->portExists(endBus.toStdString()))
1335 {
1336 messager_->showMessage(QString("Could not find port %1 within component instance %2.").
1337 arg(endBus, endInstanceName));
1338 return false;
1339 }
1340
1342
1343 if (startDirection == DirectionTypes::DIRECTION_INVALID ||
1344 endDirection == DirectionTypes::DIRECTION_INVALID ||
1345 (startDirection == DirectionTypes::IN && endDirection == DirectionTypes::IN) ||
1346 (startDirection == DirectionTypes::OUT && endDirection == DirectionTypes::OUT))
1347 {
1348 messager_->showMessage(QString("Ports %1 in %2 and %3 in %4 have incompatible directions %5 and %6.").
1349 arg(startBus, startInstanceName, endBus, endInstanceName,
1350 DirectionTypes::direction2Str(startDirection), DirectionTypes::direction2Str(endDirection)));
1351 return false;
1352 }
1353
1354 return true;
1355}
1356
1357//-----------------------------------------------------------------------------
1358// Function: PythonAPI::endsCheckForInterconnection()
1359//-----------------------------------------------------------------------------
1360bool PythonAPI::endsCheckForInterconnection(QSharedPointer<const Component> startComponent,
1361 QString const& startBus, QString const& startInstanceName, QSharedPointer<const Component> endComponent,
1362 QString const& endBus, QString const& endInstanceName)
1363{
1364 openComponent(startComponent->getVlnv().toString().toStdString());
1365
1366 ConfigurableVLNVReference startBusType = busInterface_->getBusType(startBus.toStdString());
1367 General::InterfaceMode startMode = busInterface_->getMode(startBus.toStdString());
1368 General::InterfaceMode startMonitor = busInterface_->getMonitorMode(startBus.toStdString());
1369
1370 if (!busInterface_->busInterfaceExists(startBus.toStdString()))
1371 {
1372 messager_->showMessage(QString("Could not find bus interface %1 within component instance %2.").
1373 arg(startBus, startInstanceName));
1374 return false;
1375 }
1376
1377 openComponent(endComponent->getVlnv().toString().toStdString());
1378
1379 ConfigurableVLNVReference endBusType = busInterface_->getBusType(endBus.toStdString());
1380 General::InterfaceMode endMode = busInterface_->getMode(endBus.toStdString());
1381 General::InterfaceMode endMonitor = busInterface_->getMonitorMode(endBus.toStdString());
1382
1383 if (!busInterface_->busInterfaceExists(endBus.toStdString()))
1384 {
1385 messager_->showMessage(QString("Could not find bus interface %1 within component instance %2.").
1386 arg(endBus, endInstanceName));
1387 return false;
1388 }
1389
1391
1392 if (!BusInterfaceUtilities::busDefinitionVLNVsMatch(startBusType, endBusType, library_))
1393 {
1394 messager_->showMessage(QString("Bus interfaces %1 in %2 and %3 in %4 are not of the same bus type").
1395 arg(startBus, startInstanceName, endBus, endInstanceName));
1396 return false;
1397 }
1398
1399 QVector<General::InterfaceMode> startCompatibleModes =
1400 General::getCompatibleInterfaceModesForActiveInterface(startMode);
1401
1402 if ((startMode == General::MONITOR && startMonitor != endMode) ||
1403 (endMode == General::MONITOR && endMonitor != startMode) ||
1404 !startCompatibleModes.contains(endMode))
1405 {
1406 QString startModeString = General::interfaceMode2Str(startMode);
1407 QString endModeString = General::interfaceMode2Str(endMode);
1408 if (startMode == General::MONITOR)
1409 {
1410 startModeString = General::interfaceMode2Str(startMonitor);
1411 }
1412 if (endMode == General::MONITOR)
1413 {
1414 endModeString = General::interfaceMode2Str(endMonitor);
1415 }
1416
1417 messager_->showMessage(QString(
1418 "Bus interface modes of %1 in %2 and %3 in %4 have incompatible bus interface modes %5 and %6.").
1419 arg(startBus, startInstanceName, endBus, endInstanceName, startModeString, endModeString));
1420 return false;
1421 }
1422
1423 return true;
1424}
1425
1426//-----------------------------------------------------------------------------
1427// Function: PythonAPI::removeConnection()
1428//-----------------------------------------------------------------------------
1429bool PythonAPI::removeInstanceConnection(std::string const& startInstanceName, std::string const& startBus,
1430 std::string const& endInstanceName, std::string const& endBus)
1431{
1432 std::string connectionName =
1433 connectionInterface_->getConnectionName(startInstanceName, startBus, endInstanceName, endBus);
1434
1435 return removeConnection(connectionName);
1436}
1437
1438//-----------------------------------------------------------------------------
1439// Function: PythonAPI::removeHierarchicalConnection()
1440//-----------------------------------------------------------------------------
1441bool PythonAPI::removeHierarchicalConnection(std::string const& instanceName, std::string const& instanceBus,
1442 std::string const& topBus)
1443{
1444 std::string connectionName =
1445 connectionInterface_->getHierarchicalConnectionName(instanceName, instanceBus, topBus);
1446
1447 return removeConnection(connectionName);
1448}
1449
1450//-----------------------------------------------------------------------------
1451// Function: PythonAPI::removeConnection()
1452//-----------------------------------------------------------------------------
1453bool PythonAPI::removeConnection(std::string const& connectionName)
1454{
1455 bool success = connectionInterface_->removeInterconnection(connectionName);
1456
1457 if (success == false)
1458 {
1459 messager_->showMessage(QString("Could not find connection %1.").
1460 arg(QString::fromStdString(connectionName)));
1461 }
1462
1463 return success;
1464}
1465
1466//-----------------------------------------------------------------------------
1467// Function: PythonAPI::renameConnection()
1468//-----------------------------------------------------------------------------
1469bool PythonAPI::renameConnection(std::string const& currentName, std::string const& newName)
1470{
1471 return connectionInterface_->setName(currentName, newName);
1472}
1473
1474//-----------------------------------------------------------------------------
1475// Function: PythonAPI::createAdHocConnection()
1476//-----------------------------------------------------------------------------
1477bool PythonAPI::createAdHocConnection(std::string const& startInstanceName, std::string const& startPort,
1478 std::string const& endInstanceName, std::string const& endPort)
1479{
1480 QString startInstanceNameQ = QString::fromStdString(startInstanceName);
1481 QString endInstanceNameQ = QString::fromStdString(endInstanceName);
1482 QString startPortNameQ = QString::fromStdString(startPort);
1483 QString endPortNameQ = QString::fromStdString(endPort);
1484
1485 if (!connectionEndsCheck(startInstanceNameQ, startPortNameQ, endInstanceNameQ, endPortNameQ, true))
1486 {
1487 messager_->showMessage(QString("Could not create connection"));
1488 return false;
1489 }
1490
1491 adhocConnectionInterface_->addAdHocConnection(startInstanceName, startPort, endInstanceName, endPort);
1492
1493 return true;
1494}
1495
1496//-----------------------------------------------------------------------------
1497// Function: PythonAPI::createHierarchicalAdHocConnection()
1498//-----------------------------------------------------------------------------
1499bool PythonAPI::createHierarchicalAdHocConnection(std::string const& instanceName, std::string const& instancePort,
1500 std::string const& topPort)
1501{
1502 QString instanceNameQ = QString::fromStdString(instanceName);
1503 QString instancePortQ = QString::fromStdString(instancePort);
1504 QString topPortQ = QString::fromStdString(topPort);
1505
1506 if (!instanceExists(instanceNameQ))
1507 {
1508 messager_->showMessage(QString("Could not create connection"));
1509 return false;
1510 }
1511
1512 adhocConnectionInterface_->addHierarchicalAdHocConnection(instanceName, instancePort, topPort);
1513 return true;
1514}
1515
1516//-----------------------------------------------------------------------------
1517// Function: PythonAPI::removeInstanceAdHocConnection()
1518//-----------------------------------------------------------------------------
1519bool PythonAPI::removeInstanceAdHocConnection(std::string const& startInstanceName, std::string const& startPort,
1520 std::string const& endInstanceName, std::string const& endPort)
1521{
1522 std::string connectionName =
1523 adhocConnectionInterface_->getConnectionName(startInstanceName, startPort, endInstanceName, endPort);
1524
1525 return removeAdHocConnection(connectionName);
1526}
1527
1528//-----------------------------------------------------------------------------
1529// Function: PythonAPI::removeAdHocConnection()
1530//-----------------------------------------------------------------------------
1531bool PythonAPI::removeAdHocConnection(std::string const& connectionName)
1532{
1533 bool success = adhocConnectionInterface_->removeAdHocConnection(connectionName);
1534 if (success == false)
1535 {
1536 messager_->showMessage(QString("Could not find connection %1.").
1537 arg(QString::fromStdString(connectionName)));
1538 }
1539
1540 return success;
1541}
1542
1543//-----------------------------------------------------------------------------
1544// Function: PythonAPI::removeHierarchicalAdHocConnection()
1545//-----------------------------------------------------------------------------
1546bool PythonAPI::removeHierarchicalAdHocConnection(std::string const& instanceName, std::string const& instancePort,
1547 std::string const& topPort)
1548{
1549 std::string connectionName =
1550 adhocConnectionInterface_->getHierarchicalConnectionName(instanceName, instancePort, topPort);
1551
1552 return removeAdHocConnection(connectionName);
1553}
1554
1555//-----------------------------------------------------------------------------
1556// Function: PythonAPI::renameAdHocConnection()
1557//-----------------------------------------------------------------------------
1558bool PythonAPI::renameAdHocConnection(std::string const& currentName, std::string const& newName)
1559{
1560 return adhocConnectionInterface_->setName(currentName, newName);
1561}
bool removeAdHocConnection(std::string const &connectionName)
Interface for editing address blocks.
Interface for accessing bus interfaces.
Interface for enabling plugin run using the command line arguments.
virtual QString getOutputFormat() const =0
Interface for editing fields.
ResetInterface * getSubInterface() const
void setFields(QSharedPointer< QList< QSharedPointer< Field > > > newFields)
Interface for editing file builders.
void setFileBuilders(QSharedPointer< QList< QSharedPointer< FileBuilder > > > newFileBuilders)
Interface for editing files.
void setFiles(QSharedPointer< QList< QSharedPointer< File > > > newFiles)
Interface for editing filesets.
Generator plugins can be used in the component editor and design editors to generate content for the ...
bool removeInterconnection(std::string const &connectionName)
void setAddressUnitBits(std::string const &newAddressUnitbits)
void setMemoryBlocks(QSharedPointer< QList< QSharedPointer< MemoryBlockBase > > > newMemoryBlocks)
Interface for editing memory maps and remaps.
virtual void showMessage(QString const &message) const =0
Show the given message to the user.
virtual void showError(QString const &error) const =0
Show the given error to the user.
Interface for editing parameters.
Interface for editing component ports.
std::string getVersion() const
Definition PythonAPI.cpp:92
bool removeInstanceConnections(std::string const &instanceName)
void setupLibrary(std::string const &settingsFileString)
Definition PythonAPI.cpp:84
bool renameAdHocConnection(std::string const &currentName, std::string const &newName)
bool removeComponentInstance(std::string const &instanceName)
bool removeHierarchicalConnection(std::string const &instanceName, std::string const &instanceBus, std::string const &topBus)
void removeLibraryPath(std::string const &path)
bool renameInstance(std::string const &currentName, std::string const &newName)
std::string getFirstViewName() const
bool openComponent(std::string const &vlnvString)
std::string getComponentDescription() const
void setLibraryPathActive(std::string const &path, bool isActive)
BusInterfaceInterface * getBusInterface()
void setRegistersForInterface(std::string const &mapName, std::string const &blockName)
std::vector< std::string > getActiveLibraryPaths() const
PortsInterface * getPortsInterface() const
std::vector< std::string > listVLNVs(std::string const &vendor=std::string()) const
void setFieldsForInterface(std::string const &mapName, std::string const &blockName, std::string const &registerName)
ParametersInterface * getComponentParameterInterface() const
bool createComponent(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version, StdRev revision=StdRev::Std22)
void setBlocksForInterface(std::string const &mapName)
FileSetInterface * getFileSetInterface()
void setDefaultLibraryPath(std::string const &path) const
void saveComponent()
void generateInterconnect()
std::vector< std::string > listComponentVLNVs() const
void generate(std::string const &format, std::string const &vlnv, std::string const &viewName, std::string const &outputDirectory) const
void setFilesForInterface(std::string const &setName)
std::string getDesignStdRevision() const
void setResetsForInterface(std::string const &mapName, std::string const &blockName, std::string const &registerName, std::string const &fieldName)
bool removeHierarchicalAdHocConnection(std::string const &instanceName, std::string const &instancePort, std::string const &topPort)
bool createConnection(std::string const &startInstanceName, std::string const &startBus, std::string const &endInstanceName, std::string const &endBus)
bool removeInstanceAdHocConnections(std::string const &instanceName)
std::string getComponentStdRevision() const
void setLibraryPaths(std::vector< std::string > const &paths) const
bool removeInstanceAdHocConnection(std::string const &startInstanceName, std::string const &startPort, std::string const &endInstanceName, std::string const &endPort)
int importFile(std::string const &path, std::string const &vlnv, bool overwrite=false) const
bool removeInstanceConnection(std::string const &startInstanceName, std::string const &startBus, std::string const &endInstanceName, std::string const &endBus)
bool createHierarchicalAdHocConnection(std::string const &instanceName, std::string const &instancePort, std::string const &topPort)
void addLibraryPath(std::string const &path, bool isActive=true)
bool addComponentInstance(std::string const &vlnvString, std::string const &instanceName)
void closeOpenComponent()
bool createAdHocConnection(std::string const &startInstanceName, std::string const &startPort, std::string const &endInstanceName, std::string const &endPort)
std::vector< std::string > getAllLibraryPaths() const
std::string getVLNVDirectory(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version) const
bool vlnvExistsInLibrary(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version) const
bool createHierarchicalConnection(std::string const &instanceName, std::string const &instanceBus, std::string const &topBus)
bool createDesign(std::string const &vendor, std::string const &library, std::string const &name, std::string const &version, StdRev revision=StdRev::Std22)
void closeOpenDesign()
std::string getDefaultLibraryPath() const
std::string getComponentName() const
void saveDesign()
int getFileCount() const
void setFileBuildersForInterface(std::string const &setName)
bool renameConnection(std::string const &currentName, std::string const &newName)
MemoryMapInterface * getMapInterface()
bool openDesign(std::string const &vlnvString)
Interface for editing registers.
void setRegisters(QSharedPointer< QList< QSharedPointer< RegisterBase > > > newRegisterData)
FieldInterface * getSubInterface() const
void setAddressUnitBits(int const &newAddressUnitbits)
Interface for editing resets.
void setResets(QSharedPointer< Field > containingField)
KACTUS2_API bool busDefinitionVLNVsMatch(VLNV const &firstDefinitionVLNV, VLNV const &secondDefinitionVLNV, LibraryInterface *library)