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