Skip to content

Commit

Permalink
Fixes ticket:5326 show public connectors of encrypted package
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 16, 2020
1 parent c46c1d1 commit de76be5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
34 changes: 23 additions & 11 deletions OMCompiler/Compiler/Script/Interactive.mo
Expand Up @@ -1040,15 +1040,15 @@ algorithm
algorithm
{Absyn.CREF(componentRef = cr)} := args;
Values.ENUM_LITERAL(index=access) := checkAccessAnnotationAndEncryption(AbsynUtil.crefToPath(cr), p);
if (access >= 4) then // i.e., Access.diagram
if (access >= 2) then // i.e., Access.icon
nargs := getApiFunctionNamedArgs(inStatement);
if not Flags.isSet(Flags.NF_API_NOISE) then
ErrorExt.setCheckpoint("getComponents");
end if;
outResult := getComponents(cr, useQuotes(nargs));
outResult := getComponents(cr, useQuotes(nargs), access);
if not Flags.isSet(Flags.NF_API_NOISE) then
ErrorExt.rollBack("getComponents");
end if;
end if;
else
Error.addMessage(Error.ACCESS_ENCRYPTED_PROTECTED_CONTENTS, {});
outResult := "";
Expand All @@ -1068,13 +1068,13 @@ algorithm
algorithm
{Absyn.CREF(componentRef = cr)} := args;
Values.ENUM_LITERAL(index=access) := checkAccessAnnotationAndEncryption(AbsynUtil.crefToPath(cr), p);
if (access >= 4) then // i.e., Access.diagram
if (access >= 2) then // i.e., Access.icon
if not Flags.isSet(Flags.NF_API_NOISE) then
ErrorExt.setCheckpoint("getComponentAnnotations");
end if;
evalParamAnn := Config.getEvaluateParametersInAnnotations();
Config.setEvaluateParametersInAnnotations(true);
outResult := getComponentAnnotations(cr, p);
outResult := getComponentAnnotations(cr, p, access);
Config.setEvaluateParametersInAnnotations(evalParamAnn);
if not Flags.isSet(Flags.NF_API_NOISE) then
ErrorExt.rollBack("getComponentAnnotations");
Expand Down Expand Up @@ -9822,19 +9822,21 @@ public function getComponents
a list of all components, as returned by get_nth_component."
input Absyn.ComponentRef cr;
input Boolean inBoolean;
input Integer inAccess;
output String outString;
algorithm
outString := getComponents2(cr,inBoolean);
outString := getComponents2(cr,inBoolean,inAccess);
end getComponents;

protected function getComponents2
" This function takes a `ComponentRef\', a `Program\' and an int and returns
a list of all components, as returned by get_nth_component."
input Absyn.ComponentRef inComponentRef;
input Boolean inBoolean;
input Integer inAccess;
output String outString;
algorithm
outString := matchcontinue (inComponentRef,inBoolean)
outString := matchcontinue (inComponentRef,inBoolean,inAccess)
local
Absyn.Path modelpath;
Absyn.Class cdef;
Expand All @@ -9851,8 +9853,9 @@ algorithm
FCore.Cache cache;
Boolean b, permissive;
GraphicEnvCache genv;
Integer access;

case (model_,b)
case (model_,b,access)
equation
modelpath = AbsynUtil.crefToPath(model_);
cdef = getPathedClassInProgram(modelpath, SymbolTable.getAbsyn());
Expand All @@ -9874,8 +9877,12 @@ algorithm
end if;
comps1 = getPublicComponentsInClass(cdef);
s1 = getComponentsInfo(comps1, b, "\"public\"", genv);
comps2 = getProtectedComponentsInClass(cdef);
s2 = getComponentsInfo(comps2, b, "\"protected\"", genv);
if (access >= 4) then // i.e., Access.diagram
comps2 = getProtectedComponentsInClass(cdef);
s2 = getComponentsInfo(comps2, b, "\"protected\"", genv);
else
s2 = "";
end if;
str = Util.stringDelimitListNonEmptyElts({s1,s2}, ",");
res = stringAppendList({"{",str,"}"});
then res;
Expand All @@ -9891,6 +9898,7 @@ protected function getComponentAnnotations " This function takes a `ComponentRef
components then protected ones."
input Absyn.ComponentRef inClassPath;
input Absyn.Program inProgram;
input Integer inAccess;
output String outString;
protected
Absyn.Path model_path;
Expand All @@ -9901,7 +9909,11 @@ algorithm
model_path := AbsynUtil.crefToPath(inClassPath);
cdef := getPathedClassInProgram(model_path, inProgram);
comps1 := getPublicComponentsInClass(cdef);
comps2 := getProtectedComponentsInClass(cdef);
if (inAccess >= 4) then // i.e., Access.diagram
comps2 := getProtectedComponentsInClass(cdef);
else
comps2 := {};
end if;
comps := listAppend(comps1, comps2);
outString := getComponentAnnotationsFromElts(comps, cdef, inProgram, model_path);
outString := stringAppendList({"{", outString, "}"});
Expand Down
44 changes: 15 additions & 29 deletions OMEdit/OMEditLIB/Modeling/Commands.cpp
Expand Up @@ -211,14 +211,12 @@ AddComponentCommand::AddComponentCommand(QString name, LibraryTreeItem *pLibrary
// Connector type components exists on icon view as well
mpIconComponent = new Component(name, pLibraryTreeItem, annotation, position, pComponentInfo, mpIconGraphicsView);
}
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getAccess() >= LibraryTreeItem::diagram) {
mpDiagramComponent = new Component(name, pLibraryTreeItem, annotation, position, pComponentInfo, mpDiagramGraphicsView);
}
mpDiagramComponent = new Component(name, pLibraryTreeItem, annotation, position, pComponentInfo, mpDiagramGraphicsView);
// only select the component of the active Icon/Diagram View
if (!openingClass) {
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
mpGraphicsView->clearSelection(mpIconComponent);
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getAccess() >= LibraryTreeItem::diagram) {
} else {
mpGraphicsView->clearSelection(mpDiagramComponent);
}
}
Expand All @@ -242,20 +240,14 @@ void AddComponentCommand::redoInternal()
// hide the component if it is connector and is protected
mpIconComponent->setVisible(!mpComponentInfo->getProtected());
}
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getAccess() >= LibraryTreeItem::diagram) {
mpDiagramGraphicsView->addItem(mpDiagramComponent);
mpDiagramGraphicsView->addItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->addComponentToList(mpDiagramComponent);
mpDiagramGraphicsView->deleteComponentFromOutOfSceneList(mpDiagramComponent);
mpDiagramComponent->emitAdded();
}
mpDiagramGraphicsView->addItem(mpDiagramComponent);
mpDiagramGraphicsView->addItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->addComponentToList(mpDiagramComponent);
mpDiagramGraphicsView->deleteComponentFromOutOfSceneList(mpDiagramComponent);
mpDiagramComponent->emitAdded();
if (mAddObject) {
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getAccess() >= LibraryTreeItem::diagram) {
mpDiagramGraphicsView->addComponentToClass(mpDiagramComponent);
UpdateComponentAttributesCommand::updateComponentModifiers(mpDiagramComponent, *mpDiagramComponent->getComponentInfo());
} else if (mpIconComponent) {
mpIconGraphicsView->addComponentToClass(mpIconComponent);
}
mpDiagramGraphicsView->addComponentToClass(mpDiagramComponent);
UpdateComponentAttributesCommand::updateComponentModifiers(mpDiagramComponent, *mpDiagramComponent->getComponentInfo());
}
}

Expand All @@ -275,18 +267,12 @@ void AddComponentCommand::undo()
mpIconGraphicsView->addComponentToOutOfSceneList(mpIconComponent);
mpIconComponent->emitDeleted();
}
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getAccess() >= LibraryTreeItem::diagram) {
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
mpDiagramGraphicsView->addComponentToOutOfSceneList(mpDiagramComponent);
mpDiagramComponent->emitDeleted();
}
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getAccess() >= LibraryTreeItem::diagram) {
mpDiagramGraphicsView->deleteComponentFromClass(mpDiagramComponent);
} else if (mpIconComponent) {
mpIconGraphicsView->deleteComponentFromClass(mpIconComponent);
}
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
mpDiagramGraphicsView->addComponentToOutOfSceneList(mpDiagramComponent);
mpDiagramComponent->emitDeleted();
mpDiagramGraphicsView->deleteComponentFromClass(mpDiagramComponent);
}

UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommand(Component *pComponent, const Transformation &oldTransformation,
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -271,10 +271,10 @@ LibraryTreeItem::Access LibraryTreeItem::getAccess()
return LibraryTreeItem::packageText;
} else if (mClassInformation.access.compare("Access.packageDuplicate") == 0) {
return LibraryTreeItem::packageDuplicate;
} else if (mpParentLibraryTreeItem) { // if there is no override for Access annotation then look in the parent class.
} else if (mpParentLibraryTreeItem && !mpParentLibraryTreeItem->isRootItem()) { // if there is no override for Access annotation then look in the parent class.
return mpParentLibraryTreeItem->getAccess();
} else {
return LibraryTreeItem::all;
} else { // if a class is encrypted and no Protection annotation is defined, the access annotation has the default value Access.documentation
return LibraryTreeItem::documentation;
}
} else {
return LibraryTreeItem::all;
Expand Down
10 changes: 8 additions & 2 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -4496,7 +4496,10 @@ void ModelWidget::loadComponents()
{
if (!mComponentsLoaded) {
drawModelInheritedClassComponents(this, StringHandler::Icon);
if (mpLibraryTreeItem->getAccess() >= LibraryTreeItem::diagram) {
/* We use access.icon here since getComponents will return public components in that case
* and we want to display them.
*/
if (mpLibraryTreeItem->getAccess() >= LibraryTreeItem::icon) {
getModelComponents();
drawModelIconComponents();
}
Expand All @@ -4515,7 +4518,10 @@ void ModelWidget::loadDiagramView()
drawModelInheritedClassShapes(this, StringHandler::Diagram);
getModelIconDiagramShapes(StringHandler::Diagram);
drawModelInheritedClassComponents(this, StringHandler::Diagram);
if (mpLibraryTreeItem->getAccess() >= LibraryTreeItem::diagram) {
/* We use access.icon here since getComponents will return public components in that case
* and we add them to diagram layer so that we can see and set the parameters in the parameters window.
*/
if (mpLibraryTreeItem->getAccess() >= LibraryTreeItem::icon) {
drawModelDiagramComponents();
}
mDiagramViewLoaded = true;
Expand Down

0 comments on commit de76be5

Please sign in to comment.