aurum: Add interface for searching objects by geometry. 83/280383/2
authorHosang Kim <hosang12.kim@samsung.com>
Mon, 29 Aug 2022 09:16:02 +0000 (18:16 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Mon, 29 Aug 2022 09:21:44 +0000 (18:21 +0900)
Change-Id: I144af89209892cefa640ddb4e85e5c013dcf536b

libaurum/inc/Misc/Point2D.h
libaurum/inc/Misc/Rect.h
libaurum/inc/PartialMatch.h
libaurum/inc/UiSelector.h
libaurum/src/PartialMatch.cc
libaurum/src/UiSelector.cc
org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc
org.tizen.aurum-bootstrap/src/Commands/FindElementsCommand.cc
protocol/aurum.proto

index 69bc81d9972e8d928292d326c5d443d800a9bae0..27aa0a7a77fcae843f9b8e643261bde44f8155c1 100644 (file)
@@ -73,7 +73,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    inline bool operator==(const Point2D<T>& rhs)
+    inline bool operator==(const Point2D<T>& rhs) const
     {
         return this->x == rhs.x && this->y == rhs.y;
     }
@@ -87,7 +87,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    inline bool operator!=(const Point2D<T>& rhs)
+    inline bool operator!=(const Point2D<T>& rhs) const
     {
         return !(*this == rhs);
     }
index cf9323dbaf049a3dfb896581720a54bd438cb2e1..e1aa8a3c71082fe217843897524f14e5bd2110b7 100644 (file)
@@ -128,6 +128,15 @@ public:
         return false;
     }
 
+    bool isInRect(const Rect<int> &rect) const
+    {
+        if (rect.mTopLeft.x >= mTopLeft.x && rect.mBottomRight.x <= mBottomRight.x
+            && rect.mTopLeft.y >= mTopLeft.y && rect.mBottomRight.y <= mBottomRight.y)
+            return true;
+
+        return false;
+    }
+
     /**
      * @brief Checks given Rect is same as this or not.
      *
@@ -137,7 +146,7 @@ public:
      *
      * @since_tizen 6.5
      */
-    inline bool operator==(const Rect<T>& rhs)
+    inline bool operator==(const Rect<T>& rhs) const
     {
         return this->mTopLeft == rhs.mTopLeft && this->mBottomRight == rhs.mBottomRight;
     }
@@ -151,7 +160,8 @@ public:
      *
      * @since_tizen 6.5
      */
-    inline bool operator!=(const Rect<T>& rhs){
+    inline bool operator!=(const Rect<T>& rhs) const
+    {
         return !(*this == rhs);
     }
 
index 48066836ee68f0950ba254799c51125db9f154c3..9ef7137b471af5681858f3445856d22ae4bf3254 100644 (file)
@@ -164,6 +164,18 @@ private:
      */
     static bool checkCriteria(const bool boolA, const bool boolB);
 
+    /**
+     * @brief Checks Rectangle matched or not.
+     *
+     * @param[in] rectA Rect<int>
+     * @param[in] rectB Rect<int>
+     *
+     * @return ture if matched, else false
+     *
+     * @since_tizen 7.0
+     */
+    static bool checkCriteria(const Rect<int> rectA, const Rect<int> rectB, const bool isEqual);
+
 private:
     const std::shared_ptr<UiSelector>        mSelector;
     const int                                mDepth;
index 98f544d26bdc4a8379f40aff220dc21896e113b3..4db056ef2b4a7526d9d81918586b4790df4f58b0 100644 (file)
@@ -368,6 +368,18 @@ public:
      */
     UiSelector *xpath(std::string xpath);
 
+    /**
+     * @brief Sets the search criteria to match the object's geometry.
+     *
+     * @param[in] geometry Rect<int>
+     * @param[in] isEqual bool
+     *
+     * @return UiSelector class instance
+     *
+     * @since_tizen 7.0
+     */
+    UiSelector *geometry(Rect<int> geometry, bool isEqual);
+
 public:
     std::string mId;
     std::string mAutomationId;
@@ -390,6 +402,7 @@ public:
     bool mMatchTextPartialMatch;
     bool mMatchXPath;
     bool mMatchOcrText;
+    bool mMatchGeometry;
 
     bool mMatchChecked;
     bool mMatchCheckable;
@@ -420,8 +433,12 @@ public:
     bool mIsvisible;
     bool mIsselectable;
 
+    bool mGeometryIsEqual;
+
     std::vector<std::shared_ptr<UiSelector>> mChild;
     std::shared_ptr<UiSelector> mParent;
+
+    Rect<int> mGeometry;
 };
 
 }
index ba030d190358f360f0643067012871096985bf33..1e0d0180b131ea621bf65b6b2dbcc2fd14462f47 100644 (file)
@@ -46,6 +46,16 @@ bool PartialMatch::checkCriteria(const bool boolA, const bool boolB)
     return boolA != boolB;
 }
 
+bool PartialMatch::checkCriteria(const Rect<int> rectA, const Rect<int> rectB, bool isEqual)
+{
+    if (isEqual) {
+        return rectA != rectB;
+    }
+    else {
+        return !rectA.isInRect(rectB);
+    }
+}
+
 std::string PartialMatch::debugPrint()
 {
     return mSelector->description();
@@ -106,6 +116,10 @@ bool PartialMatch::checkCriteria(const std::shared_ptr<UiSelector> selector,
         node->updateRoleName();
         if (checkCriteria(selector->mRole, node->getRole(), 0)) return false;
     }
+    if (selector->mMatchGeometry) {
+        node->updateExtents();
+        if (checkCriteria(selector->mGeometry, node->getScreenBoundingBox(), selector->mGeometryIsEqual)) return false;
+    }
     if (selector->mMatchChecked && checkCriteria(selector->mIschecked, node->isChecked())) return false;
     if (selector->mMatchCheckable && checkCriteria(selector->mIscheckable, node->isCheckable())) return false;
     if (selector->mMatchClickable && checkCriteria(selector->mIsclickable, node->isClickable())) return false;
index 8157b18d4332551852faed45d4687c0df26d5057..74822c9c26cacbe275855e4461ee8b9dd6f3a3fc 100644 (file)
@@ -28,7 +28,7 @@ UiSelector::UiSelector()
   mMatchFocused{}, mMatchFocusable{}, mMatchScrollable{}, mMatchSelected{}, mMatchShowing{}, mMatchActive{}, mMatchVisible{},
   mMatchSelectable{}, mMinDepth{}, mMaxDepth{}, mIschecked{}, mIscheckable{}, mIsclickable{}, mIsenabled{},
   mIsfocused{}, mIsfocusable{}, mIsscrollable{}, mIsselected{}, mIsshowing{}, mIsactive{}, mIsvisible{},
-  mIsselectable{}, mChild{}, mParent{}
+  mIsselectable{}, mChild{}, mParent{}, mGeometry{}
 {
 }
 
@@ -46,6 +46,7 @@ std::string UiSelector::description()
     if(!this->mPkg.empty()) ss << "\"mPkg\":\"" << this->mPkg << "\", ";
     if(!this->mType.empty()) ss << "\"mType\":\"" << this->mType << "\", ";
     if(!this->mStyle.empty()) ss << "\"mStyle\":\"" << this->mStyle << "\", ";
+    if(this->mMatchGeometry) ss << "\"mGeometry\":\"" << this->mGeometry.mTopLeft.x << "//" << this->mGeometry.mTopLeft.y << "//" << this->mGeometry.width() << "//" << this->mGeometry.height() << "\", ";
     if(this->mMatchId) ss << "\"mMatchId\":\"" << ((this->mMatchId)?"true":"false") << "\", ";
     if(this->mMatchAutomationId) ss << "\"mMatchAutomationId\":\"" << ((this->mMatchAutomationId)?"true":"false") << "\", ";
     if(this->mMatchRole) ss << "\"mMatchRole\":\"" << ((this->mMatchRole)?"true":"false") << "\", ";
@@ -56,6 +57,7 @@ std::string UiSelector::description()
     if(this->mMatchPkg) ss << "\"mMatchPkg\":\"" << ((this->mMatchPkg)?"true":"false") << "\", ";
     if(this->mMatchType) ss << "\"mMatchType\":\"" << ((this->mMatchType)?"true":"false") << "\", ";
     if(this->mMatchStyle) ss << "\"mMatchStyle\":\"" << ((this->mMatchStyle)?"true":"false" )<< "\", ";
+    if(this->mMatchGeometry) ss << "\"mMatchGeometry\":\"" << ((this->mMatchGeometry)?"true":"false" )<< "\", ";
     if(this->mMinDepth) ss << "\"mMinDepth\":\"" << this->mMinDepth << "\", ";
     if(this->mMaxDepth) ss << "\"mMaxDepth\":\"" << this->mMaxDepth << "\", ";
     if(this->mMatchChecked) ss << "\"mMatchChecked\":\"" << ((this->mMatchChecked)?"true":"false") << "\", ";
@@ -275,3 +277,11 @@ UiSelector *UiSelector::fromParent(std::shared_ptr<UiSelector> parent)
     mParent = parent;
     return this;
 }
+
+UiSelector *UiSelector::geometry(Rect<int> geometry, bool isEqual)
+{
+    this->mGeometry = geometry;
+    this->mGeometryIsEqual = isEqual;
+    this->mMatchGeometry = true;
+    return this;
+}
\ No newline at end of file
index ed92078d7bf84a536f2bd4da30502781b0f36d0d..ce89249731c43130974b5359e824c4905aabfc54 100644 (file)
@@ -69,6 +69,7 @@ std::shared_ptr<UiSelector> FindElementCommand::getSelector(void)
     if(mRequest->_textpartialmatch_case()) sel->textPartialMatch(mRequest->textpartialmatch());
     if(mRequest->_xpath_case())            sel->xpath(mRequest->xpath());
     if(mRequest->_ocrtext_case())          sel->ocrText(mRequest->ocrtext());
+    if(mRequest->_geometry_case())         sel->geometry(Rect<int>{mRequest->geometry().x(), mRequest->geometry().y(), mRequest->geometry().x() + mRequest->geometry().width(), mRequest->geometry().y() + mRequest->geometry().height()}, true);
 
     return sel;
 }
index bc2119c0b9da518747f7304d7c78d126d7821191..937e31f859ac40d297cc234ab21ac57e03dba0b1 100644 (file)
@@ -69,6 +69,7 @@ std::vector<std::shared_ptr<UiSelector>> FindElementsCommand::getSelectors(void)
     if(mRequest->_textpartialmatch_case()) sel->textPartialMatch(mRequest->textpartialmatch());
     if(mRequest->_xpath_case())            sel->xpath(mRequest->xpath());
     if(mRequest->_ocrtext_case())          sel->ocrText(mRequest->ocrtext());
+    if(mRequest->_geometry_case())         sel->geometry(Rect<int>{mRequest->geometry().x(), mRequest->geometry().y(), mRequest->geometry().x() + mRequest->geometry().width(), mRequest->geometry().y() + mRequest->geometry().height()}, false);
 
     return std::vector<std::shared_ptr<UiSelector>>{sel};
 }
index 0e076f9f475dce1a5fcb8b715dcc5f4e655fbbee..e5e308587194d0356aa49c42938c1206f0060be1 100644 (file)
@@ -193,7 +193,11 @@ message ReqFindElement {
       string ocrText = 21;
    }
 
-   repeated ReqFindElement children = 22;
+   oneof _geometry {
+     Rect geometry = 22;
+   }
+
+   repeated ReqFindElement children = 23;
 }
 
 message RspFindElement {
@@ -284,7 +288,12 @@ message ReqFindElements {
    oneof _ocrtext {
       string ocrText = 21;
    }
-   repeated ReqFindElements children = 22;
+
+   oneof _geometry {
+     Rect geometry = 22;
+   }
+
+   repeated ReqFindElements children = 23;
 }
 
 message RspFindElements {