15#include <KactusAPI/KactusAPI.h>
35#include <IPXACTmodels/common/ConfigurableVLNVReference.h>
36#include <IPXACTmodels/common/validators/ParameterValidator.h>
38#include <IPXACTmodels/Component/Component.h>
39#include <IPXACTmodels/Component/Port.h>
40#include <IPXACTmodels/Component/View.h>
41#include <IPXACTmodels/Component/MemoryMap.h>
42#include <IPXACTmodels/Component/AddressBlock.h>
43#include <IPXACTmodels/Component/MemoryBlockBase.h>
44#include <IPXACTmodels/Component/RegisterBase.h>
45#include <IPXACTmodels/Component/Register.h>
46#include <IPXACTmodels/Component/Field.h>
47#include <IPXACTmodels/Component/validators/FieldValidator.h>
48#include <IPXACTmodels/Component/validators/EnumeratedValueValidator.h>
49#include <IPXACTmodels/Component/validators/RegisterValidator.h>
50#include <IPXACTmodels/Component/validators/RegisterFileValidator.h>
51#include <IPXACTmodels/Component/validators/AddressBlockValidator.h>
52#include <IPXACTmodels/Component/validators/SubspaceMapValidator.h>
53#include <IPXACTmodels/Component/validators/MemoryMapValidator.h>
54#include <IPXACTmodels/Component/validators/FileSetValidator.h>
55#include <IPXACTmodels/Component/validators/FileValidator.h>
57#include <IPXACTmodels/Design/Interconnection.h>
58#include <IPXACTmodels/Design/AdHocConnection.h>
59#include <IPXACTmodels/Design/ActiveInterface.h>
60#include <IPXACTmodels/Design/Design.h>
63#include <IPXACTmodels/DesignConfiguration/DesignConfiguration.h>
70 constructMemoryValidators();
71 constructMemoryInterface();
72 constructFileSetInterface();
80 library_->searchForIPXactFiles();
88 return KactusAPI::getVersion().toStdString();
96 QStringList locations = KactusAPI::getAllLibraryPaths();
98 std::vector<std::string> paths;
99 for (
auto const& path : locations)
101 paths.push_back(path.toStdString());
112 KactusAPI::setLibraryPathActive(QString::fromStdString(path), isActive);
120 KactusAPI::addLibraryPath(QString::fromStdString(path), isActive);
128 if (KactusAPI::removeLibraryPath(QString::fromStdString(path)) ==
false)
130 messager_->showError(QStringLiteral(
"Error: Cannot remove default library path"));
139 QStringList locations = KactusAPI::getActiveLibraryPaths();
141 std::vector<std::string> paths;
142 for (
auto const& path : locations)
144 paths.push_back(path.toStdString());
155 return portsInterface_;
163 return componentParameterInterface_;
171 return mapInterface_;
179 return fileSetInterface_;
187 return busInterface_;
195 QStringList libraryPaths;
196 for (
auto const& path : paths)
198 libraryPaths.append(QString::fromStdString(path));
201 KactusAPI::setLibraryPaths(libraryPaths);
209 return KactusAPI::getDefaultLibraryPath().toStdString();
217 KactusAPI::setDefaultLibraryPath(QString::fromStdString(path));
225 VLNV targetVLNV(VLNV::COMPONENT, QString::fromStdString(vlnv));
227 return KactusAPI::importFile(QString::fromStdString(path), targetVLNV, overwrite);
234 std::string
const& outputDirectory)
const
236 VLNV componentVLNV(VLNV::COMPONENT, QString::fromStdString(vlnv));
237 KactusAttribute::Implementation implementation = KactusAttribute::HW;
239 QString fileFormat = QString::fromStdString(format).toLower();
241 QStringList availableFormats;
244 for (
auto plugin : KactusAPI::getPlugins())
258 if (generator !=
nullptr)
260 KactusAPI::runGenerator(generator, componentVLNV, QString::fromStdString(viewName),
261 QString::fromStdString(outputDirectory), implementation,
nullptr);
265 availableFormats.sort(Qt::CaseInsensitive);
266 messager_->showError(QStringLiteral(
"No generator found for format %1. Available options are: %2").arg(
267 fileFormat, availableFormats.join(
',')));
276 return library_->getAllVLNVs().count();
284 std::vector<std::string> vlnvStrings;
286 for (
auto const& itemVLNV : library_->getAllVLNVs())
288 vlnvStrings.push_back(itemVLNV.toString().toStdString());
299 std::vector<std::string> componentVLNVs;
301 for (
auto const& itemVLNV : library_->getAllVLNVs())
303 if (itemVLNV.getType() == VLNV::COMPONENT)
305 componentVLNVs.push_back(itemVLNV.toString().toStdString());
309 return componentVLNVs;
316 std::string
const& version)
const
318 if (vendor.empty() || library.empty() || name.empty() || version.empty())
320 messager_->showError(
"Error in given VLNV.");
324 return library_->contains(VLNV(VLNV::INVALID,
325 QString::fromStdString(vendor),
326 QString::fromStdString(library),
327 QString::fromStdString(name),
328 QString::fromStdString(version)));
335 std::string
const& version,
StdRev revision )
337 if (vendor.empty() || library.empty() || name.empty() || version.empty())
339 messager_->showError(
"Error in given VLNV.");
343 VLNV newComponentVLNV;
344 newComponentVLNV.setVendor(QString::fromStdString(vendor));
345 newComponentVLNV.setLibrary(QString::fromStdString(library));
346 newComponentVLNV.setName(QString::fromStdString(name));
347 newComponentVLNV.setVersion(QString::fromStdString(version));
348 newComponentVLNV.setType(VLNV::COMPONENT);
350 if (library_->contains(newComponentVLNV))
356 ? Document::Revision::Std22 : Document::Revision::Std14;
358 QSharedPointer<Component> component = QSharedPointer<Component>(
new Component(newComponentVLNV, docRevision));
360 component->setHierarchy(KactusAttribute::FLAT);
361 component->setFirmness(KactusAttribute::MUTABLE);
362 component->setImplementation(KactusAttribute::HW);
363 component->setVersion(KactusAPI::getVersionFileString());
365 QString directory = KactusAPI::getDefaultLibraryPath();
366 QString vlnvDir =
"/" + newComponentVLNV.getVendor() +
"/" + newComponentVLNV.getLibrary() +
"/" +
367 newComponentVLNV.getName() +
"/" + newComponentVLNV.getVersion();
369 directory += vlnvDir;
371 if (!library_->writeModelToFile(directory, component))
373 messager_->showError(
"Error saving file to disk.");
386 std::string
const& name, std::string
const& version)
const
389 documentVLNV.setVendor(QString::fromStdString(vendor));
390 documentVLNV.setLibrary(QString::fromStdString(library));
391 documentVLNV.setName(QString::fromStdString(name));
392 documentVLNV.setVersion(QString::fromStdString(version));
394 return KactusAPI::getDocumentFilePath(documentVLNV).toStdString();
402 if (activeComponent_)
404 QStringList componentNames = activeComponent_->getViewNames();
405 if (!componentNames.isEmpty())
407 return componentNames.first().toStdString();
411 QSharedPointer<View> newView(
new View(
"mockView"));
412 activeComponent_->getViews()->append(newView);
413 return newView->name().toStdString();
417 return std::string();
425 QString componentVLNV = QString::fromStdString(vlnvString);
426 QSharedPointer<Document> componentDocument = getDocument(componentVLNV);
427 if (componentDocument)
429 QSharedPointer<Component> component = componentDocument.dynamicCast<Component>();
432 parameterFinder_->setComponent(component);
433 portValidator_->componentChange(component->getViews());
434 portsInterface_->setPorts(component->getPorts());
436 parameterValidator_->componentChange(component->getChoices(), component->getRevision());
437 componentParameterInterface_->setParameters(component->getParameters());
438 componentParameterInterface_->setChoices(component->getChoices());
440 mapValidator_->componentChange(component);
441 mapInterface_->setMemoryMaps(component);
443 fileSetInterface_->setFileSets(component->getFileSets());
445 busInterface_->setBusInterfaces(component);
447 activeComponent_ = component;
448 messager_->showMessage(QString(
"Component %1 is open").arg(componentVLNV));
453 messager_->showError(QString(
"The given VLNV %1 is not a component").arg(componentVLNV));
459 messager_->showError(QString(
"Could not open document with VLNV %1").arg(componentVLNV));
467QSharedPointer<Document> PythonAPI::getDocument(QString
const& vlnvString)
const
469 QStringList vlnvArray = vlnvString.split(
':');
470 if (vlnvArray.size() != 4)
472 messager_->
showError(QString(
"The given VLNV %1 is not valid").arg(vlnvString));
473 return QSharedPointer<Document>();
476 VLNV targetVLNV(VLNV::COMPONENT, vlnvArray.at(0), vlnvArray.at(1), vlnvArray.at(2), vlnvArray.at(3));
477 return library_->getModel(targetVLNV);
485 if (activeComponent_)
487 messager_->showMessage(QString(
"Component %1 is closed").arg(activeComponent_->getVlnv().toString()));
490 activeComponent_ = QSharedPointer<Component>();
498 if (activeComponent_)
500 return activeComponent_->getVlnv().getName().toStdString();
504 return std::string();
513 if (activeComponent_)
515 return activeComponent_->getDescription().toStdString();
519 return std::string();
528 if (activeComponent_)
530 return Document::toStdString(activeComponent_->getRevision());
533 return std::string();
541 if (activeComponent_)
543 messager_->showMessage(QString(
"Saving component %1 ...").arg(activeComponent_->getVlnv().toString()));
546 if (library_->writeModelToFile(activeComponent_))
548 messager_->showMessage(QString(
"Save complete"));
552 messager_->showError(QString(
"Could not save component %1").arg(activeComponent_->getVlnv().toString()));
561void PythonAPI::constructMemoryValidators()
563 QSharedPointer<EnumeratedValueValidator> enumValidator(
new EnumeratedValueValidator(expressionParser_));
564 QSharedPointer<FieldValidator>fieldValidator(
new FieldValidator(
565 expressionParser_, enumValidator, parameterValidator_));
566 QSharedPointer<RegisterValidator> registerValidator (
new RegisterValidator(
567 expressionParser_, fieldValidator, parameterValidator_));
568 QSharedPointer<RegisterFileValidator> registerFileValidator(
569 new RegisterFileValidator(expressionParser_, registerValidator, parameterValidator_,
570 Document::Revision::Unknown));
572 QSharedPointer<AddressBlockValidator> blockValidator(
new AddressBlockValidator(
573 expressionParser_, registerValidator, registerFileValidator, parameterValidator_,
574 Document::Revision::Unknown));
576 QSharedPointer<SubspaceMapValidator> subspaceValidator(
577 new SubspaceMapValidator(expressionParser_, parameterValidator_, Document::Revision::Unknown));
579 QSharedPointer<MemoryMapValidator> mapValidator(
580 new MemoryMapValidator(expressionParser_, blockValidator, subspaceValidator, QSharedPointer<Component>()));
582 mapValidator_ = mapValidator;
588void PythonAPI::constructMemoryInterface()
590 QSharedPointer<SubspaceMapValidator> subspaceValidator = mapValidator_->getSubspaceValidator();
591 QSharedPointer<AddressBlockValidator> blockValidator = mapValidator_->getAddressBlockValidator();
592 QSharedPointer<RegisterValidator> registerValidator = blockValidator->getRegisterValidator();
593 QSharedPointer<FieldValidator> fieldValidator = registerValidator->getFieldValidator();
595 ResetInterface* resetInterface(
new ResetInterface(fieldValidator, expressionParser_, expressionFormatter_));
596 FieldInterface* fieldInterface(
597 new FieldInterface(fieldValidator, expressionParser_, expressionFormatter_, resetInterface));
599 ModeReferenceInterface* modeReferenceInterface(
new ModeReferenceInterface());
601 AccessPolicyInterface* accessPolicyInterface(
new AccessPolicyInterface(modeReferenceInterface));
603 RegisterInterface* registerInterface(
604 new RegisterInterface(registerValidator, expressionParser_, expressionFormatter_, fieldInterface,
605 accessPolicyInterface));
607 AddressBlockInterface* blockInterface(
new AddressBlockInterface(blockValidator, expressionParser_,
608 expressionFormatter_, busInterface_, registerInterface, componentParameterInterface_));
609 SubspaceMapInterface* subspaceInterface(
new SubspaceMapInterface(
610 subspaceValidator, expressionParser_, expressionFormatter_, busInterface_, componentParameterInterface_));
612 mapInterface_ =
new MemoryMapInterface(mapValidator_, expressionParser_, expressionFormatter_);
614 mapInterface_->setAddressBlockInterface(blockInterface);
615 mapInterface_->setSubspaceMapInterface(subspaceInterface);
616 mapInterface_->setModeReferenceInterface(modeReferenceInterface);
626 QString mapNameQT = QString::fromStdString(mapName);
627 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
630 sendMemoryMapNotFoundError(mapNameQT);
635 blockInterface->
setAddressUnitBits(containingMap->getAddressUnitBits().toStdString());
645 QString mapNameQT = QString::fromStdString(mapName);
646 QString blockNameQT = QString::fromStdString(blockName);
648 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
651 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
654 interfacePointer->
setRegisters(containingBlock->getRegisterData());
656 expressionParser_->parseExpression(containingMap->getAddressUnitBits()).toInt());
660 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
665 sendMemoryMapNotFoundError(mapNameQT);
673 std::string
const& registerName)
676 mapInterface_->getAddressBlockInterface()->
getSubInterface()->getSubInterface();
678 QString mapNameQT = QString::fromStdString(mapName);
679 QString blockNameQT = QString::fromStdString(blockName);
680 QString registerNameQT = QString::fromStdString(registerName);
682 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
685 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
688 QSharedPointer<Register> containingRegister = getRegister(containingBlock, registerNameQT);
689 if (containingRegister)
691 interfacePointer->
setFields(containingRegister->getFields());
695 sendRegisterNotFoundError(mapNameQT, blockNameQT, registerNameQT);
700 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
705 sendMemoryMapNotFoundError(mapNameQT);
713 std::string
const& registerName, std::string
const& fieldName)
716 mapInterface_->getAddressBlockInterface()->getSubInterface()->getSubInterface()->getSubInterface();
718 QString mapNameQT = QString::fromStdString(mapName);
719 QString blockNameQT = QString::fromStdString(blockName);
720 QString registerNameQT = QString::fromStdString(registerName);
721 QString fieldNameQT = QString::fromStdString(fieldName);
723 QSharedPointer<MemoryMap> containingMap = getMemoryMap(mapNameQT);
726 QSharedPointer<AddressBlock> containingBlock = getAddressBock(containingMap, blockNameQT);
729 QSharedPointer<Register> containingRegister = getRegister(containingBlock, registerNameQT);
730 if (containingRegister)
732 QSharedPointer<Field> containingField = getField(containingRegister, fieldNameQT);
735 interfacePointer->
setResets(containingField);
739 sendFieldNotFoundError(mapNameQT, blockNameQT, registerNameQT, fieldNameQT);
744 sendRegisterNotFoundError(mapNameQT, blockNameQT, registerNameQT);
749 sendAddressBlockNotFoundError(mapNameQT, blockNameQT);
754 sendMemoryMapNotFoundError(mapNameQT);
761QSharedPointer<MemoryMap> PythonAPI::getMemoryMap(QString
const& mapName)
const
763 for (
auto map : *activeComponent_->getMemoryMaps())
765 if (map->name() == mapName)
771 return QSharedPointer<MemoryMap>();
777QSharedPointer<AddressBlock> PythonAPI::getAddressBock(QSharedPointer<MemoryMap> containingMap,
778 QString
const& blockName)
const
780 for (
auto baseBlock : *containingMap->getMemoryBlocks())
782 QSharedPointer<AddressBlock> block = baseBlock.dynamicCast<AddressBlock>();
783 if (block && block->name() == blockName)
789 return QSharedPointer<AddressBlock>();
795QSharedPointer<Register> PythonAPI::getRegister(QSharedPointer<AddressBlock> containingBlock,
796 QString
const& registerName)
const
798 for (
auto baseRegister : *containingBlock->getRegisterData())
800 QSharedPointer<Register> currentRegister = baseRegister.dynamicCast<Register>();
801 if (currentRegister && currentRegister->name() == registerName)
803 return currentRegister;
807 return QSharedPointer<Register>();
813QSharedPointer<Field> PythonAPI::getField(QSharedPointer<Register> containingRegister, QString
const& fieldName)
816 for (
auto currentField : *containingRegister->getFields())
818 if (currentField->name() == fieldName)
824 return QSharedPointer<Field>();
830void PythonAPI::constructFileSetInterface()
832 QSharedPointer<FileValidator> newFileValidator(
new FileValidator(expressionParser_));
833 QSharedPointer<FileSetValidator> newFileSetValidator(
834 new FileSetValidator(newFileValidator, expressionParser_));
836 FileInterface* fileInterface =
new FileInterface(newFileValidator, expressionParser_, expressionFormatter_);
838 FileBuilderInterface* fileBuilderInterface =
new FileBuilderInterface(expressionParser_, expressionFormatter_);
840 fileSetInterface_ =
new FileSetInterface(
841 newFileSetValidator, expressionParser_, expressionFormatter_, fileInterface, fileBuilderInterface);
849 FileInterface* fileInterface = fileSetInterface_->getFileInterface();
851 QString fileSetNameQT = QString::fromStdString(setName);
852 QSharedPointer<FileSet> containingFileSet = getFileSet(fileSetNameQT);
853 if (!containingFileSet)
855 sendFileSetNotFoundError(fileSetNameQT);
859 fileInterface->
setFiles(containingFileSet->getFiles());
865QSharedPointer<FileSet> PythonAPI::getFileSet(QString
const& setName)
const
867 for (
auto fileSet : *activeComponent_->getFileSets())
869 if (fileSet->name() == setName)
875 return QSharedPointer<FileSet>();
885 QString fileSetNameQT = QString::fromStdString(setName);
886 QSharedPointer<FileSet> containingFileSet = getFileSet(fileSetNameQT);
887 if (!containingFileSet)
889 sendFileSetNotFoundError(fileSetNameQT);
893 builderInterface->
setFileBuilders(containingFileSet->getDefaultFileBuilders());
900 std::string
const& name, std::string
const& version,
StdRev revision )
902 if (vendor.empty() || library.empty() || name.empty() || version.empty())
904 messager_->showError(
"Error in given VLNV.");
908 VLNV componentVLNV(VLNV::DESIGN,
909 QString::fromStdString(vendor),
910 QString::fromStdString(library),
911 QString::fromStdString(name),
912 QString::fromStdString(version));
914 if (
createComponent(vendor, library, name, version, revision) ==
false)
916 messager_->showError(
"Error in creating containing component.");
920 VLNV designVLNV(VLNV::DESIGN, componentVLNV.getVendor(), componentVLNV.getLibrary(),
921 componentVLNV.getName() +
".design", componentVLNV.getVersion());
922 VLNV desConfVLNV(VLNV::DESIGNCONFIGURATION, componentVLNV.getVendor(), componentVLNV.getLibrary(),
923 componentVLNV.getName()+
".designcfg", componentVLNV.getVersion());
925 if (library_->contains(designVLNV))
930 QSharedPointer<DesignConfigurationInstantiation> hierarchicalInstantiation
931 (
new DesignConfigurationInstantiation(desConfVLNV.getName() +
"_" + desConfVLNV.getVersion()));
933 QSharedPointer<ConfigurableVLNVReference> tempReference(
new ConfigurableVLNVReference(desConfVLNV));
934 hierarchicalInstantiation->setDesignConfigurationReference(tempReference);
936 QSharedPointer<View> newHierarchicalView(
new View(QStringLiteral(
"hierarchical")));
937 newHierarchicalView->setDesignConfigurationInstantiationRef(hierarchicalInstantiation->name());
939 activeComponent_->getDesignConfigurationInstantiations()->append(hierarchicalInstantiation);
940 activeComponent_->getViews()->append(newHierarchicalView);
942 auto design = QSharedPointer<Design>(
new Design(designVLNV, Document::Revision::Std14));
943 design->setVersion(KactusAPI::getVersionFileString());
944 design->setDesignImplementation(KactusAttribute::HW);
947 auto designConf = QSharedPointer<DesignConfiguration>(
new DesignConfiguration(desConfVLNV, Document::Revision::Std14));
948 designConf->setDesignRef(designVLNV);
949 designConf->setDesignConfigImplementation(KactusAttribute::HW);
950 designConf->setVersion(KactusAPI::getVersionFileString());
952 if (QString directory = KactusAPI::getDefaultLibraryPath() +
"/" + designVLNV.toString(QStringLiteral(
"/"));
953 !library_->writeModelToFile(activeComponent_) ||
954 !library_->writeModelToFile(directory, design) ||
955 !library_->writeModelToFile(directory, designConf))
957 messager_->showError(
"Error saving file to disk.");
961 openDesign(designVLNV.toString().toStdString());
973 return Document::toStdString(activeDesign_->getRevision());
976 return std::string();
982void PythonAPI::sendMemoryMapNotFoundError(QString
const& mapName)
const
984 messager_->
showError(QString(
"Could not find memory map %1 within component %2").
985 arg(mapName, activeComponent_->getVlnv().toString()));
991void PythonAPI::sendAddressBlockNotFoundError(QString
const& mapName, QString
const& blockName)
const
993 messager_->showError(QString(
"Could not find address block %1 within memory map %2 in component %3").
994 arg(blockName, mapName, activeComponent_->getVlnv().toString()));
1000void PythonAPI::sendRegisterNotFoundError(QString
const& mapName, QString
const& blockName,
1001 QString
const& registerName)
const
1003 messager_->showError(
1004 QString(
"Could not find register %1 within address block %2 in memory map %3 in component %4").
1005 arg(registerName, blockName, mapName, activeComponent_->getVlnv().toString()));
1011void PythonAPI::sendFieldNotFoundError(QString
const& mapName, QString
const& blockName,
1012 QString
const& registerName, QString
const& fieldName)
const
1014 messager_->showError(
1015 QString(
"Could not find field %1 within register %2 in address block %3 in memory map %4 in component %5").
1016 arg(fieldName, registerName, blockName, mapName, activeComponent_->getVlnv().toString()));
1022void PythonAPI::sendFileSetNotFoundError(QString
const& setName)
const
1024 messager_->showError(QString(
"Could not find file set %1 within component %2").
1025 arg(setName, activeComponent_->getVlnv().toString()));
1033 QString designVLNV = QString::fromStdString(vlnvString);
1034 QSharedPointer<Document> designDocument = getDocument(designVLNV);
1037 QSharedPointer<Design> design = designDocument.dynamicCast<Design>();
1040 activeDesign_ = design;
1041 messager_->showMessage(QString(
"Design %1 is open").arg(designVLNV));
1043 instanceInterface_->setComponentInstances(activeDesign_);
1044 connectionInterface_->setInterconnections(activeDesign_);
1045 adhocConnectionInterface_->setConnections(activeDesign_);
1051 messager_->showError(QString(
"The given VLNV %1 is not a design").arg(designVLNV));
1057 messager_->showError(QString(
"Could not open document with VLNV %1").arg(designVLNV));
1069 messager_->showMessage(QString(
"Design %1 is closed").arg(activeDesign_->getVlnv().toString()));
1072 activeDesign_ = QSharedPointer<Design>();
1082 messager_->showMessage(QString(
"Saving design %1 ...").arg(activeDesign_->getVlnv().toString()));
1084 if (library_->writeModelToFile(activeDesign_))
1086 messager_->showMessage(QString(
"Save complete"));
1090 messager_->showError(QString(
"Could not save design %1").arg(activeDesign_->getVlnv().toString()));
1102 messager_->showMessage(QString(
"No open design"));
1106 QString combinedVLNV = QString::fromStdString(vlnvString);
1107 QSharedPointer<Document> instanceDocument = getDocument(combinedVLNV);
1108 if (!instanceDocument)
1110 messager_->showMessage(QString(
"Could not find document %1").arg(combinedVLNV));
1114 QSharedPointer<Component> instanceComponent = instanceDocument.dynamicCast<Component>();
1115 if (!instanceComponent)
1117 messager_->showMessage(QString(
"%1 is not a component").arg(combinedVLNV));
1121 QStringList vlnvList = combinedVLNV.split(
":");
1122 if (vlnvList.size() < 4)
1124 messager_->showMessage(QString(
"The VLNV %1 is not correct").arg(combinedVLNV));
1128 std::string newVendor = vlnvList.at(0).toStdString();
1129 std::string newLibrary = vlnvList.at(1).toStdString();
1130 std::string newName = vlnvList.at(2).toStdString();
1131 std::string newVersion = vlnvList.at(3).toStdString();
1133 instanceInterface_->addComponentInstance(instanceName);
1134 return instanceInterface_->setComponentReference(instanceName, newVendor, newLibrary, newName, newVersion);
1144 messager_->showMessage(QString(
"No open design"));
1148 return instanceInterface_->removeComponentInstance(instanceName);
1156 return connectionInterface_->removeInstanceInterconnections(instanceName);
1164 return adhocConnectionInterface_->removeInstanceAdHocConnections(instanceName);
1172 return instanceInterface_->setName(currentName, newName);
1179 std::string
const& endInstanceName, std::string
const& endBus)
1181 QString startInstanceNameQ = QString::fromStdString(startInstanceName);
1182 QString endInstanceNameQ = QString::fromStdString(endInstanceName);
1183 QString startBusNameQ = QString::fromStdString(startBus);
1184 QString endBusNameQ = QString::fromStdString(endBus);
1186 if (!connectionEndsCheck(startInstanceNameQ, startBusNameQ, endInstanceNameQ, endBusNameQ,
false))
1188 messager_->showMessage(QString(
"Could not create connection"));
1192 connectionInterface_->addInterconnection(startInstanceName, startBus, endInstanceName, endBus);
1201 std::string
const& topBus)
1203 QString instanceNameQ = QString::fromStdString(instanceName);
1204 QString instanceBusNameQ = QString::fromStdString(instanceBus);
1205 QString topBusQ = QString::fromStdString(topBus);
1207 if (!instanceExists(instanceNameQ))
1209 messager_->showMessage(QString(
"Could not create connection"));
1213 connectionInterface_->addHierarchicalInterconnection(instanceName, instanceBus, topBus);
1221bool PythonAPI::connectionEndsCheck(QString
const& startInstanceName, QString
const& startBus,
1222 QString
const& endInstanceName, QString
const& endBus,
bool isAdHocConnection)
1224 if (instanceExists(startInstanceName) ==
false || instanceExists(endInstanceName) ==
false)
1229 QSharedPointer<ConfigurableVLNVReference> startComponenReference =
1230 instanceInterface_->getComponentReference(startInstanceName.toStdString());
1231 QSharedPointer<ConfigurableVLNVReference> endComponentReference =
1232 instanceInterface_->getComponentReference(endInstanceName.toStdString());
1233 QSharedPointer<const Document> startDocument = library_->getModelReadOnly(*startComponenReference.data());
1234 QSharedPointer<const Document> endDocument = library_->getModelReadOnly(*endComponentReference.data());
1235 QSharedPointer<const Component> startComponent = startDocument.dynamicCast<
const Component>();
1236 QSharedPointer<const Component> endComponent = endDocument.dynamicCast<
const Component>();
1239 if (isAdHocConnection)
1241 return endsCheckForAdHoc(
1242 startComponent, startBus, startInstanceName, endComponent, endBus, endInstanceName);
1246 return endsCheckForInterconnection(
1247 startComponent, startBus, startInstanceName, endComponent, endBus, endInstanceName);
1254bool PythonAPI::instanceExists(QString
const& instanceName)
const
1256 if (!instanceInterface_->instanceExists(instanceName.toStdString()))
1258 messager_->showMessage(QString(
"Could not find component instance %1 within %2").
1259 arg(instanceName, activeDesign_->getVlnv().toString()));
1263 QSharedPointer<ConfigurableVLNVReference> instanceComponenReference =
1264 instanceInterface_->getComponentReference(instanceName.toStdString());
1266 if (!instanceComponenReference)
1268 messager_->showMessage(QString(
"Component instance %1 does not have a component reference").
1273 QSharedPointer<const Document> instanceDocument =
1274 library_->getModelReadOnly(*instanceComponenReference.data());
1275 if (!instanceDocument)
1277 messager_->showMessage(QString(
"Component instance %1 references a non-existing document %2").
1278 arg(instanceName, instanceComponenReference->toString()));
1282 QSharedPointer<const Component> instanceComponent = instanceDocument.dynamicCast<
const Component>();
1283 if (!instanceComponent)
1285 messager_->showMessage(QString(
"Component instance %1 component reference %1 is not a component").
1286 arg(instanceName, instanceComponenReference->toString()));
1296bool PythonAPI::endsCheckForAdHoc(QSharedPointer<const Component> startComponent, QString
const& startBus,
1297 QString
const& startInstanceName, QSharedPointer<const Component> endComponent, QString
const& endBus,
1298 QString
const& endInstanceName)
1300 openComponent(startComponent->getVlnv().toString().toStdString());
1302 DirectionTypes::Direction startDirection =
1303 DirectionTypes::str2Direction(QString::fromStdString(portsInterface_->getDirection(
1304 startBus.toStdString())), DirectionTypes::DIRECTION_INVALID);
1306 if (!portsInterface_->portExists(startBus.toStdString()))
1308 messager_->showMessage(QString(
"Could not find port %1 within component instance %2.").
1309 arg(startBus, startInstanceName));
1313 openComponent(endComponent->getVlnv().toString().toStdString());
1314 DirectionTypes::Direction endDirection = DirectionTypes::str2Direction(QString::fromStdString(
1315 portsInterface_->getDirection(endBus.toStdString())), DirectionTypes::DIRECTION_INVALID);
1317 if (!portsInterface_->portExists(endBus.toStdString()))
1319 messager_->showMessage(QString(
"Could not find port %1 within component instance %2.").
1320 arg(endBus, endInstanceName));
1326 if (startDirection == DirectionTypes::DIRECTION_INVALID ||
1327 endDirection == DirectionTypes::DIRECTION_INVALID ||
1328 (startDirection == DirectionTypes::IN && endDirection == DirectionTypes::IN) ||
1329 (startDirection == DirectionTypes::OUT && endDirection == DirectionTypes::OUT))
1331 messager_->showMessage(QString(
"Ports %1 in %2 and %3 in %4 have incompatible directions %5 and %6.").
1332 arg(startBus, startInstanceName, endBus, endInstanceName,
1333 DirectionTypes::direction2Str(startDirection), DirectionTypes::direction2Str(endDirection)));
1343bool PythonAPI::endsCheckForInterconnection(QSharedPointer<const Component> startComponent,
1344 QString
const& startBus, QString
const& startInstanceName, QSharedPointer<const Component> endComponent,
1345 QString
const& endBus, QString
const& endInstanceName)
1347 openComponent(startComponent->getVlnv().toString().toStdString());
1349 ConfigurableVLNVReference startBusType = busInterface_->getBusType(startBus.toStdString());
1350 General::InterfaceMode startMode = busInterface_->getMode(startBus.toStdString());
1351 General::InterfaceMode startMonitor = busInterface_->getMonitorMode(startBus.toStdString());
1353 if (!busInterface_->busInterfaceExists(startBus.toStdString()))
1355 messager_->showMessage(QString(
"Could not find bus interface %1 within component instance %2.").
1356 arg(startBus, startInstanceName));
1360 openComponent(endComponent->getVlnv().toString().toStdString());
1362 ConfigurableVLNVReference endBusType = busInterface_->getBusType(endBus.toStdString());
1363 General::InterfaceMode endMode = busInterface_->getMode(endBus.toStdString());
1364 General::InterfaceMode endMonitor = busInterface_->getMonitorMode(endBus.toStdString());
1366 if (!busInterface_->busInterfaceExists(endBus.toStdString()))
1368 messager_->showMessage(QString(
"Could not find bus interface %1 within component instance %2.").
1369 arg(endBus, endInstanceName));
1377 messager_->showMessage(QString(
"Bus interfaces %1 in %2 and %3 in %4 are not of the same bus type").
1378 arg(startBus, startInstanceName, endBus, endInstanceName));
1382 QVector<General::InterfaceMode> startCompatibleModes =
1383 General::getCompatibleInterfaceModesForActiveInterface(startMode);
1385 if ((startMode == General::MONITOR && startMonitor != endMode) ||
1386 (endMode == General::MONITOR && endMonitor != startMode) ||
1387 !startCompatibleModes.contains(endMode))
1389 QString startModeString = General::interfaceMode2Str(startMode);
1390 QString endModeString = General::interfaceMode2Str(endMode);
1391 if (startMode == General::MONITOR)
1393 startModeString = General::interfaceMode2Str(startMonitor);
1395 if (endMode == General::MONITOR)
1397 endModeString = General::interfaceMode2Str(endMonitor);
1400 messager_->showMessage(QString(
1401 "Bus interface modes of %1 in %2 and %3 in %4 have incompatible bus interface modes %5 and %6.").
1402 arg(startBus, startInstanceName, endBus, endInstanceName, startModeString, endModeString));
1413 std::string
const& endInstanceName, std::string
const& endBus)
1415 std::string connectionName =
1416 connectionInterface_->getConnectionName(startInstanceName, startBus, endInstanceName, endBus);
1418 return removeConnection(connectionName);
1425 std::string
const& topBus)
1427 std::string connectionName =
1428 connectionInterface_->getHierarchicalConnectionName(instanceName, instanceBus, topBus);
1430 return removeConnection(connectionName);
1436bool PythonAPI::removeConnection(std::string
const& connectionName)
1440 if (success ==
false)
1442 messager_->
showMessage(QString(
"Could not find connection %1.").
1443 arg(QString::fromStdString(connectionName)));
1454 return connectionInterface_->setName(currentName, newName);
1461 std::string
const& endInstanceName, std::string
const& endPort)
1463 QString startInstanceNameQ = QString::fromStdString(startInstanceName);
1464 QString endInstanceNameQ = QString::fromStdString(endInstanceName);
1465 QString startPortNameQ = QString::fromStdString(startPort);
1466 QString endPortNameQ = QString::fromStdString(endPort);
1468 if (!connectionEndsCheck(startInstanceNameQ, startPortNameQ, endInstanceNameQ, endPortNameQ,
true))
1470 messager_->showMessage(QString(
"Could not create connection"));
1474 adhocConnectionInterface_->addAdHocConnection(startInstanceName, startPort, endInstanceName, endPort);
1483 std::string
const& topPort)
1485 QString instanceNameQ = QString::fromStdString(instanceName);
1486 QString instancePortQ = QString::fromStdString(instancePort);
1487 QString topPortQ = QString::fromStdString(topPort);
1489 if (!instanceExists(instanceNameQ))
1491 messager_->showMessage(QString(
"Could not create connection"));
1495 adhocConnectionInterface_->addHierarchicalAdHocConnection(instanceName, instancePort, topPort);
1503 std::string
const& endInstanceName, std::string
const& endPort)
1505 std::string connectionName =
1506 adhocConnectionInterface_->getConnectionName(startInstanceName, startPort, endInstanceName, endPort);
1508 return removeAdHocConnection(connectionName);
1514bool PythonAPI::removeAdHocConnection(std::string
const& connectionName)
1517 if (success ==
false)
1519 messager_->
showMessage(QString(
"Could not find connection %1.").
1520 arg(QString::fromStdString(connectionName)));
1530 std::string
const& topPort)
1532 std::string connectionName =
1533 adhocConnectionInterface_->getHierarchicalConnectionName(instanceName, instancePort, topPort);
1535 return removeAdHocConnection(connectionName);
1543 return adhocConnectionInterface_->setName(currentName, newName);
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.
Interface for editing parameters.
Interface for editing component ports.
std::string getVersion() const
bool removeInstanceConnections(std::string const &instanceName)
void setupLibrary(std::string const &settingsFileString)
bool renameAdHocConnection(std::string const ¤tName, 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 ¤tName, 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 ®isterName)
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
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 ®isterName, 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)
std::string getDefaultLibraryPath() const
std::string getComponentName() const
void setFileBuildersForInterface(std::string const &setName)
bool renameConnection(std::string const ¤tName, 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)